Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
 Welcome to our latest new user Nicron ! (Registered 2024-05-21) You are not logged in - nap
CSDb User Forums


Forums > CSDb Entries > Release id #178591 : Dataliner - Native Python 2.7 Script
2019-06-22 11:48
Moloch

Registered: Jan 2002
Posts: 2897
Release id #178591 : Dataliner - Native Python 2.7 Script

Submitted by zzarko [PM] on 22 June 2019
I have modified dataliner script to work with Python 2 and Python 3, so no two versions are needed. You can find it at:

https://pastebin.com/18VzwuPg

I have tested the output of original Python 2 script and modified-one with Python 2 and Python 3, and diff says that the outputs are identical (although, I tested with only one input file, so maybe more testing is needed).
2019-06-23 11:03
ChristopherJam

Registered: Aug 2004
Posts: 1381
And here's a shorter version, with the multiple passes over the data removed and the temporary file with one text line per data byte optimised out.

from __future__ import print_function
import sys

print()

if len(sys.argv)<4:
    print("Please enter all needed parameters:")
    print("Example: dataliner file.prg data.txt 100")
    print()
    print("This converts the binary data of file.prg into C64 V2 Basic data lines beginning "+
        "with line 100, stored in the file data.txt, which you can integrate in your Basic "+
        "listing with any text editor and copy and paste into VICE.")
    sys.exit()

with open(sys.argv[1], "rb") as f:
    if sys.version_info < (3, 0):
        src=[ord(v) for v in f.read()]
    else:
        src= f.read()

length=len(src)

if length < 3:
    print("Aborting. Selected binary file is too small!")
    sys.exit()

load_addr = src[1]*256+src[0]
line_number = int(sys.argv[3])

with open(sys.argv[2],'w+') as h:
    for i in range(2,length,16): # Die ersten beiden Adressbytes des C64 PRGs fliegen raus
        print("{} data {}".format(line_number, ",".join(str(x) for x in src[i:i+16])), file=h)
        line_number += 1

print("No. of bytes in DATA stream, omiting the first  2 address-bytes:", length-2)
print("File is loading in C64 memory at ${:04x}".format(load_addr))
print("Read into C64 memory from {} to {} + {}".format(load_addr, load_addr, length-3))
print("Location of text file with C64 Basic DATAs:   " + sys.argv[2])
print()

2019-06-25 16:01
Mr.Ammo
Account closed

Registered: Oct 2002
Posts: 228
Nice one, Christopher Jam.
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
Menace/Spaceballs
Nicron
Linus/MSL
Zorch
Guests online: 56
Top Demos
1 Next Level  (9.8)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.7)
5 Edge of Disgrace  (9.6)
6 No Bounds  (9.6)
7 Comaland 100%  (9.6)
8 Uncensored  (9.6)
9 Bromance  (9.5)
10 Lunatico  (9.5)
Top onefile Demos
1 Layers  (9.6)
2 It's More Fun to Com..  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 TRSAC, Gabber & Pebe..  (9.5)
7 Rainbow Connection  (9.5)
8 Dawnfall V1.1  (9.5)
9 Quadrants  (9.5)
10 Daah, Those Acid Pil..  (9.5)
Top Groups
1 Oxyron  (9.3)
2 Booze Design  (9.3)
3 Censor Design  (9.3)
4 Crest  (9.3)
5 Nostalgia  (9.3)
Top Swappers
1 Derbyshire Ram  (10)
2 Jerry  (9.8)
3 Violator  (9.8)
4 Acidchild  (9.7)
5 Starlight  (9.6)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.029 sec.