Binary data for the X16

Chat about anything CX16 related that doesn't fit elsewhere
User avatar
kliepatsch
Posts: 247
Joined: Thu Oct 08, 2020 9:54 pm

Binary data for the X16

Post by kliepatsch »



On 9/30/2021 at 4:44 AM, rje said:




Hey, that doesn't write bytes to the output channel, it creates a text file containing the Python expression "[12, 13, 14, 0, 80, 0, 90, 0, 10, 0, 12, 13, 14]". The binary file should have 12 bytes in it, since there are 12 byte values in the concatted array. Maybe I'm doing something wrong?



Just tested it, and that's what happens in Python 2. In Python 3 it does indeed write a binary file. In Python 2 it is "bytearray()" instead of "bytes()", then it works as intended. Not sure why "bytes()" doesn't throw an error in Python 2.

 

 


On 9/29/2021 at 7:34 PM, rje said:




Note that he has to first break down larger numbers, and encode strings into bytes.  He might have to do some custom coding if endianness is a problem.



Partially true. You can convert other things into bytearrays. E.g. appending a 16-bit integer to a bytearray is


existing_bytearray += (65535).to_bytes(2,"little")

where the argument 2 states that it should become 2 bytes, and "little" or "big" endian can be used. There's also an option for signed integers. Strings can be dealt with as


existing_bytearray += ("hello world").encode("utf-8")

Although encoding strings to PETSCII may require some extra code...

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

Binary data for the X16

Post by rje »



On 9/30/2021 at 1:07 AM, kliepatsch said:




Although encoding strings to PETSCII may require some extra code...



Doesn't need to be said!

BruceMcF
Posts: 1336
Joined: Fri Jul 03, 2020 4:27 am

Binary data for the X16

Post by BruceMcF »



On 9/29/2021 at 11:48 PM, rje said:




...



* * *



Now.



Can we have multi-line scripts, complete with BEGIN and END options?



I think variables would be no problem, so we could have variable assignment in the action blurbs.



Associative arrays are, I think, just out of reach, without some shoehorning.  I'd defer that until the rest of it works beautifully.



The most interesting parts of regular expressions will probably never work here.  Too big.



AFAIR, a bit thing V7 awk did not have was user definable functions.

It had constant string regular expressions, but couldn't get a regular expression from a variable.

The differences between the V7 awk and the "One True Awk" is described here.

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

Binary data for the X16

Post by rje »



On 9/30/2021 at 1:43 PM, BruceMcF said:




AFAIR, a bit thing V7 awk did not have was user definable functions.



It had constant string regular expressions, but couldn't get a regular expression from a variable.



The differences between the V7 awk and the "One True Awk" is described here.



Thank you for the link.  I'm reading it now.

I'm also writing a throw-away thing to do some very careless things in a vaguely AWKlike manner.

BruceMcF
Posts: 1336
Joined: Fri Jul 03, 2020 4:27 am

Binary data for the X16

Post by BruceMcF »



On 9/30/2021 at 4:56 PM, rje said:




Thank you for the link.  I'm reading it now.



I'm also writing a throw-away thing to do some very careless things in a vaguely AWKlike manner.



The other big thing for some things ... like fully correct csv parsing ... is that since regular expressions cannot be assigned to variables, they cannot be assigned to parsing input fields. So I'd likely have a separate csv-lint program to make sure that the "," separator works.

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

Binary data for the X16

Post by rje »


Now that I'm thinking about it, I'm also thinking about the reasonable scope for the X16.  These sorts of UNIX-like operations aren't very common on Commodore 8 bit machines.

I've already found the plain-old catenate pattern useful.  I suspect one that matches a substring and prints the matching line and line number would be useful, so a condition to match a string, and an action for printing NR and the line itself would be nice.  I wonder if vprintf() is as easy as it sounds?

 

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

Binary data for the X16

Post by rje »


Let's continue the AWK discussion in an AWK topic.

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

Binary data for the X16

Post by rje »



 

Post Reply