Coverage for pyilper/lifcore.py: 86%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1#!/usr/bin/python3
2# -*- coding: utf-8 -*-
3#
4# LIF utilities
5#
6# Python classes to handle LIF image files
7# derived from the LIF utilities of Tony Duell
8# Copyright (c) 2008 A. R. Duell
9# Python Version (c) 2015 Joachim Siebold
10#
11# This program is free software; you can redistribute it and/or
12# modify it under the terms of the GNU General Public License
13# as published by the Free Software Foundation; either version 2
14# of the License, or (at your option) any later version.
15#
16# This program is distributed in the hope that it will be useful,
17# but WITHOUT ANY WARRANTY; without even the implied warranty of
18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19# GNU General Public License for more details.
20#
21# You should have received a copy of the GNU General Public License
22# along with this program; if not, write to the Free Software
23# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24#
25# LIF image file classes ---------------------------------------------------
26#
27# Changelog
28# 08.01.16 - jsi:
29# fixed getLifString if string contains blanks
30# 16.01.16 - jsi
31# fixed missing file types
32# 23.01.16 - jsi
33# fixed getLifString to handle empty strings
34# 30.01.16 - jsi
35# added LIFUTILS_REQUIRED_VERSION constant
36# 17.10.2016 jsi
37# - set required version of lifutils to 1.7.6
38# 01.12.2016 jsi
39# - use wcat41 instead of wall to display wall files
40# 28.10.2017 jsi
41# - lifutils UUID constant added
42# 30.10.2017 jsi
43# - LIFUTILS_PATH module variable and functions added
44# 11.11.2017 jsi
45# - set required version of lifutils to 1.7.7
46# 31.05.2019 jsi
47# - set required version of lifutils to 1.7.9
48# - text75 is now liftext75
49# 04.06.2019 jsi
50# - lexcat75 added to display information of HP-75 lex files
51#
52# core constants and functions to handle lif image files
53#
55import pathlib
58dict_finfo_type={0x0001:["TEXT","liftext"],0x00FF:["D-LEX","lexcat71"],0xE020:["WAXM41",""],0xE030:["XM41",""],0xE040:["ALL41","wcat41"],0xE050:["KEY41","key41"],0xE052:["TXT75","liftext75"],0xE053:["APP75",""],0xE058:["DAT75",""],0xE060:["STA41","stat41"],0xE070:["X-M41",""],0xE080:["PGM41","decomp41"],0xE088:["BAS75",""],0xE089:["LEX75","lexcat75"],0xE08A:["WKS75",""],0xE08B:["ROM75",""],0xE0D0:["SDATA","sdata"],0xE0D1:["TEXT (S)","liftext"],0xE0F0:["DAT71",""],0xE0F1:["DAT71 (S)",""],0xE204:["BIN71",""],0xE205:["BIN71 (S)",""],0xE206:["BIN71 (P)",""],0xE207:["BIN71 (SP)",""],0xE208:["LEX71","lexcat71"],0xE209:["LEX71 (S)","lexcat71"],0xE20A:["LEX71 (P)","lexcat71"],0xE20B:["LEX71 (SP)","lexcat71"],0xE20C:["KEY71",""],0xE20D:["KEY71 (S)",""],0xE214:["BAS71",""],0xE215:["BAS71 (S)",""],0xE216:["BAS71 (P)",""],0xE217:["BAS71 (SP)",""],0xE218:["FTH71",""],0xE219:["FTH71 (S)",""],0xE21A:["FTH71 (P)",""],0xE21B:["FTH71 (SP)",""],0xE222:["GRA71",""],0xE224:["ADR71",""],0xE22E:["SYM71",""],0xE21C:["ROM71",""]}
60dict_finfo_name={"TEXT":0x0001,"D-LEX":0x00FF,"WAXM41":0xE020,"XM41":0xE030,"ALL41":0xE040,"KEY41":0xE050,"TXT75":0xE052,"APP75":0xE053,"DAT75":0xE058,"STA41":0xE060,"X-M41":0xE070,"PGM41":0xE080,"BAS75":0xE088,"LEX75":0xE089,"WKS75":0xE08A,"ROM75":0xE08B,"SDATA":0xE0D0,"TEXT (S)":0xE0D1,"DAT71":0xE0F0,"DAT71 (S)":0xE0F1,"BIN71":0xE204,"BIN71 (S)":0xE205,"BIN71 (P)":0xE206,"BIN71 (SP)":0xE207,"LEX71":0xE208,"LEX71 (S)":0xE209,"LEX71 (P)":0xE20A,"LEX71 (SP)":0xE20B,"KEY71":0xE20C,"KEY71 (S)":0xE20D,"BAS71":0xE214,"BAS71 (S)":0xE215,"BAS71 (P)":0xE216,"BAS71 (SP)":0xE217,"FTH71":0xE218,"FTH71 (S)":0xE219,"FTH71 (P)":0xE21A,"FTH71 (SP)":0xE21B,"GRA71":0xE222,"ADR71":0xE224,"SYM71":0xE22E,"ROM71":0xE21C}
61#
62# Minimum Version number of LIFUTILS
63#
64LIFUTILS_REQUIRED_VERSION=10709
65#
66# GUID of a lifutils > 1.7.x windows installation
67#
68LIFUTILS_UUID="{0C786F40-D1C6-4681-9B1D-AFC920428192}"
69#
70# current path to lifutils programs
71#
72LIFUTILS_PATH=""
73#
74# set/get current path to lifutils programs
75def set_lifutils_path(path):
76 global LIFUTILS_PATH
77 LIFUTILS_PATH=path
79def get_lifutils_path():
80 return LIFUTILS_PATH
81#
82# add LIFUTILS_PATH to program
83#
84def add_path(cmd):
85 lifutils_path= get_lifutils_path()
86 if lifutils_path !="":
87 p=pathlib.Path(lifutils_path) / cmd
88 cmd= str(p)
89 return(cmd)
92# get numeric filetype for a file file type name
93#
94def get_finfo_name(ftype_name):
95 if ftype_name in dict_finfo_name:
96 return(dict_finfo_name[ftype_name])
97 else:
98 return None
100#
101# get file type name and additional information for a numeric file type
102#
103def get_finfo_type(ftype):
104 if ftype in dict_finfo_type:
105 return(dict_finfo_type[ftype])
106 else:
107 return None
109#
110# store an inter into a byte array
111#
112def putLifInt(data,offset,length,value):
113 i=length - 1
114 while i >= 0:
115 data[offset+i]= value & 0xFF
116 value=value >> 8
117 i-=1
118 return
119#
120# get an integer from a byt array
121#
122def getLifInt(data,offset,length):
123 i=0
124 value=0
125 while i < length:
126 value= (value <<8) + data[offset+i]
127 i+=1
128 return value
130def bcdtodec(c):
131 return(((c&0xf0)>>4)*10 +(c &0x0f))
133#
134# get time and date from a byte string
135#
136def getLifDateTime(b,offset):
137 day=bcdtodec(b[offset])
138 month=bcdtodec(b[offset+1])
139 year=bcdtodec(b[offset+2])
140 hour=bcdtodec(b[offset+3])
141 minute=bcdtodec(b[offset+4])
142 sec=bcdtodec(b[offset+5])
143 return("{:02d}-{:02d}-{:02d} {:02d}:{:02d}:{:02d}".format(day,month,year,hour,minute,sec))
144#
145# get a lif string, also those that contain a blank in between
146#
147def getLifString(data,offset,length):
148 str_list= []
149 j= -1
150 for i in range(length):
151 if data[offset+i] != 0x20:
152 j=i
153 if j == -1:
154 return ""
155 else:
156 for i in range(j+1):
157 str_list.append(chr(data[offset+i]))
158 return "".join(str_list)