1
+ # Run this script with XAS99 to assemble all files
2
+ # See https://endlos99.github.io/xdt99/
3
+ #
4
+ # If you can't run powershell scripts research this command locally:
5
+ # Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process
6
+ import os , glob , shutil , re
7
+ from itertools import chain
8
+
9
+ #Functions
10
+ def get_work_file (filename ):
11
+ return WORK_FOLDER + filename
12
+
13
+ def get_unlinked_string (object_files ):
14
+ unlinked_files = []
15
+ for object_file in object_files :
16
+ unlinked_files .append (get_work_file (object_file + TEMP_SUFFIX ))
17
+ return ' ' .join (unlinked_files )
18
+
19
+ def link_test_files (linked_file , object_files ):
20
+ unlinked_files_string = get_unlinked_string (object_files )
21
+ link_command_1 = 'xas99.py -l {source} -o {output}'
22
+ link_command_2 = link_command_1 .format (source = unlinked_files_string , output = get_work_file (linked_file ))
23
+ os .system (link_command_2 )
24
+
25
+ #
26
+ # MAIN
27
+ #
28
+
29
+ WORK_FOLDER = './Fiad/'
30
+ PUBLISH_FOLDER = './Publish/'
31
+ TEMP_SUFFIX = '.obj'
32
+
33
+ #Assemble Src and Tests
34
+ files1 = os .scandir ('.//Src' )
35
+ files2 = os .scandir ('.//Tests' )
36
+ files = chain (files1 , files2 )
37
+
38
+ os .makedirs (os .path .dirname (WORK_FOLDER ), exist_ok = True )
39
+ os .makedirs (os .path .dirname (PUBLISH_FOLDER ), exist_ok = True )
40
+
41
+ # Assemble the files
42
+ for file_obj in files :
43
+ print ('Assembling ' + file_obj .name )
44
+ list_file = get_work_file (file_obj .name .replace ('.asm' , '.lst' ))
45
+ obj_file = get_work_file (file_obj .name .replace ('.asm' , TEMP_SUFFIX ))
46
+ assemble_command_1 = 'xas99.py -q -S -R {source} -L {list} -o {obj}'
47
+ assemble_command_2 = assemble_command_1 .format (source = file_obj .path , list = list_file , obj = obj_file )
48
+ os .system (assemble_command_2 )
49
+
50
+ #
51
+ publish_files = [
52
+ 'ARRAY' ,
53
+ 'MEMBUF' ,
54
+ 'VAR'
55
+ ]
56
+
57
+ # Add version information to some files
58
+ comment = ': Memory Management - 1.4.0 - https://github.com/bkrug/TI-string-buffer ' # This line is intentionally 76 char long
59
+ for publish_file in publish_files :
60
+ fileContent = ''
61
+ with open (WORK_FOLDER + publish_file + TEMP_SUFFIX , 'r' ) as file :
62
+ fileContent = file .read ().rstrip ()
63
+ lastLineNo = fileContent [len (fileContent ) - 4 :]
64
+ newContent = fileContent [:len (fileContent ) - 80 ] + comment + lastLineNo
65
+ with open (WORK_FOLDER + publish_file + TEMP_SUFFIX , 'w' ) as file :
66
+ file .write (newContent )
67
+
68
+ # Create Test Runners
69
+ print ('Linking Unit Test Runners' )
70
+ temp_files = [ 'TESTFRAM' , 'ARRYTST' , 'ARRAY' , 'MEMBUF' , 'VAR' ]
71
+ link_test_files ('ARRYRUN.obj' , temp_files )
72
+
73
+ temp_files = [ 'TESTFRAM' , 'MEMTST' , 'MEMBUF' , 'VAR' ]
74
+ link_test_files ('MEMRUN.obj' , temp_files )
75
+
76
+ # Add some files to a Disk image
77
+ disk_image = PUBLISH_FOLDER + 'BufferAndArray.dsk'
78
+ print ('Creating disk image' + disk_image )
79
+ os .system ('xdm99.py -X sssd ' + disk_image )
80
+ for obj_file in publish_files :
81
+ add_command_1 = 'xdm99.py {disk_image} -a {obj_file} -f DIS/FIX80'
82
+ add_command_2 = add_command_1 .format (disk_image = disk_image , obj_file = WORK_FOLDER + obj_file + TEMP_SUFFIX )
83
+ os .system (add_command_2 )
84
+
85
+ # Create a version of the object files that can be used by XDT99
86
+ print ('Creating headerless object files' )
87
+ for file_obj in publish_files :
88
+ shutil .copy (WORK_FOLDER + file_obj + TEMP_SUFFIX , PUBLISH_FOLDER + file_obj + '.noheader.obj' )
89
+ shutil .move (WORK_FOLDER + file_obj + TEMP_SUFFIX , PUBLISH_FOLDER + file_obj + '.obj' )
90
+
91
+ # Add TIFILES header to all object files
92
+ print ('Adding TIFILES header' )
93
+ for file_obj in publish_files :
94
+ header_command_1 = 'xdm99.py -T {object_file} -f DIS/FIX80 -o {object_file}'
95
+ header_command_2 = header_command_1 .format (object_file = PUBLISH_FOLDER + file_obj + '.obj' )
96
+ os .system (header_command_2 )
97
+
98
+ #Clean up
99
+ for file in glob .glob (WORK_FOLDER + '*.lst' ):
100
+ os .remove (file )
101
+ for file in glob .glob (WORK_FOLDER + '*' + TEMP_SUFFIX ):
102
+ if not file .endswith ('ARRYRUN.obj' ) and not file .endswith ('MEMRUN.obj' ):
103
+ os .remove (file )
0 commit comments