Create a SEQ file in BASIC

Tutorials and help articles.

(Posts require approval. See pinned post.)
Forum rules
Post guides, tutorials, and other instructional content here.

This topic area requires approval, so please be patient while we review content to make sure it fits the expectations for this topic area.

Tech support questions should be asked in Hardware or Software support.
rje
Posts: 1263
Joined: Mon Apr 27, 2020 10:00 pm
Location: Dallas Area

Create a SEQ file in BASIC

Post by rje »


I could swear I saw an easier way to handle those nulls.  Ah something like this:

...
120 GET#8, A$
130 A=ASC(A$ + CHR$(0)) :REM NULL PROTECTION PATTERN
140 IF ST <> 0 THEN 200
...

Here's where I found it, this time around.  I think I've also seen it on the "C64 Programming" Facebook page.

https://www.lemon64.com/forum/viewtopic.php?p=181978&sid=5e9b35d1a6b8e77a89c45bb383be70cf#181978










Quote:



30 print asc(t$): rem display the byte in ASCII code

Make that










Code:

30 print asc(t$+chr$(0))

so it won't barf when it encounters chr$(0) which get# returns as empty string.

=====================================================================================================

* Upside: terser code.

* Downside: string cat is probably slower.

* Downside: might encourage the garbage collector to run.

 

^ So, good for small files, bad for big files?

 

 

TomXP411
Posts: 1785
Joined: Tue May 19, 2020 8:49 pm

Create a SEQ file in BASIC

Post by TomXP411 »



42 minutes ago, rje said:




* Upside: terser code.

* Downside: string cat is probably slower.

* Downside: might encourage the garbage collector to run.

^ So, good for small files, bad for big files?



Yeah, you're trading an IF statement for some string concatenation. I'll go run both and see what we get.

 

TomXP411
Posts: 1785
Joined: Tue May 19, 2020 8:49 pm

Create a SEQ file in BASIC

Post by TomXP411 »


A quick test shows my version is slightly faster...

writing 25K to disk (CHR$(0)-CHR$(255) 100 times) took about 28 seconds.

Reading back using the IF took 53 seconds

Reading back using ASC(A$+CHR$(0)) took 54 seconds.

And since it's not spawning 25,600 tiny strings, I'm going to say that the IF version is a better choice in any situation I can think of where you need binary data.


10 REM CREATE TEST FILE
15 TI$="000000":PRINT "WRITING TEST FILE"
20 OPEN 8,8,8,"@0:TESTFILE,S,W"
30 FOR I=1 TO 100
40 FOR C=0 TO 255
50 PRINT#8,CHR$(C);
60 NEXT C,I
70 CLOSE 8
80 PRINT TI$
100 OPEN 8,8,8,"TESTFILE,S,R"
105 PRINT "READ TEST 1":TI$="000000"
110 A=0
120 GET#8,A$
130 IF ST<>0 GOTO 200
140 IF A$<>""THEN A=ASC(A$)
150 GOTO 120
200 CLOSE 8
210 PRINT TI$
300 OPEN 8,8,8,"TESTFILE,S,R"
305 PRINT "READ TEST 2":TI$="000000"
320 GET#8,A$
330 IF ST<>0 GOTO 360
340 A=ASC(A$+CHR$(0))
350 GOTO 320
360 CLOSE 8
370 PRINT TI$


 

TomXP411
Posts: 1785
Joined: Tue May 19, 2020 8:49 pm

Create a SEQ file in BASIC

Post by TomXP411 »



1 hour ago, SlithyMatt said:




I plan on making one for assembly development as soon as that kernal code is stable and fully functioning in the emulator. Unfortunately, progress on that has been stalled for many months.



I'm waiting for similar reasons; there are promised changes coming to the emulator and the ROMs, but they have not actually been happening.... and with the emulator in this weird, quantum "released but not released" state, I don't want to write any code for the current iteration.

I don't think the guys realize how much not having a binary release is holding the community back right now.

 

rje
Posts: 1263
Joined: Mon Apr 27, 2020 10:00 pm
Location: Dallas Area

Create a SEQ file in BASIC

Post by rje »


With me, it's a kind of reluctance to write VERA sprite code in C.  That's my next project.

We've got examples.  It's not like there isn't any code.

But there's something about it that just makes me wince.

 

Snickers11001001
Posts: 140
Joined: Wed Jan 20, 2021 6:43 pm

Create a SEQ file in BASIC

Post by Snickers11001001 »


I always overcomplicated things!  

 

My approach back in the day was to do it all in one line for the read, null handling, and conversion to a number:

20 GET#8, A$: A=1+(A$=""):IF A THEN A=ASC(A$)

 

 

Funny how there are so many different ways.   

BTW, I have no idea how mine performed, it never mattered when you knew you were waiting on the 1541! 

 

 

rje
Posts: 1263
Joined: Mon Apr 27, 2020 10:00 pm
Location: Dallas Area

Create a SEQ file in BASIC

Post by rje »


I guess we could fix GET#.

Meh, probably not.

 

Scott Robison
Posts: 952
Joined: Fri Mar 19, 2021 9:06 pm

Create a SEQ file in BASIC

Post by Scott Robison »



1 hour ago, rje said:




I guess we could fix GET#.



Meh, probably not.



I seem to recall through the haze of history that there was a relatively simple patch for BASIC published in Compute's Gazette or similar that fixed ASC to return 0 for an empty string. That would probably be simple to integrate, and it would be compatible with v2, just one less error case to check. People who already check for empty string would not see a difference, and the rest would have it easier.

TomXP411
Posts: 1785
Joined: Tue May 19, 2020 8:49 pm

Create a SEQ file in BASIC

Post by TomXP411 »



1 hour ago, rje said:




I guess we could fix GET#.



Meh, probably not.



 



 


53 minutes ago, Scott Robison said:




I seem to recall through the haze of history that there was a relatively simple patch for BASIC published in Compute's Gazette or similar that fixed ASC to return 0 for an empty string. That would probably be simple to integrate, and it would be compatible with v2, just one less error case to check. People who already check for empty string would not see a difference, and the rest would have it easier.



IMO, both should be done. GET# should return a 0 when the data on the channel is a zero. And ASC should not choke on a zero length string. 

 

Snickers11001001
Posts: 140
Joined: Wed Jan 20, 2021 6:43 pm

Create a SEQ file in BASIC

Post by Snickers11001001 »




EDITED:   Well, I tried both the Plus/4 and C128 emulators and, on both, the following worked fine:

10: A$=""
20 A=ASC(A$)
30 PRINT A

So, just a matter of tracing the assembly code for ASC() and seeing where the difference is.  ('just' hahaha)

Post Reply