forked from johanberntsson/ozmoo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make.rb
2790 lines (2463 loc) · 98.4 KB
/
make.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# specialised make for Ozmoo
require 'fileutils'
$is_windows = (ENV['OS'] == 'Windows_NT')
if $is_windows then
# Paths on Windows
$X64 = "C:\\ProgramsWoInstall\\WinVICE-3.1-x64\\x64.exe -autostart-warp" # -autostart-delay-random"
$X128 = "C:\\ProgramsWoInstall\\WinVICE-3.1-x64\\x128 -80col -autostart-delay-random"
$XPLUS4 = "C:\\ProgramsWoInstall\\WinVICE-3.1-x64\\xplus4 -autostart-delay-random"
$MEGA65 = "\"C:\\Program Files\\xemu\\xmega65.exe\" -syscon" # -syscon is a workaround for a serious xemu bug
$C1541 = "C:\\ProgramsWoInstall\\WinVICE-3.1-x64\\c1541.exe"
$EXOMIZER = "C:\\ProgramsWoInstall\\Exomizer-3.1.0\\win32\\exomizer.exe"
$ACME = "C:\\ProgramsWoInstall\\acme0.97win\\acme\\acme.exe"
$commandline_quotemark = "\""
else
# Paths on Linux
$X64 = "x64 -autostart-delay-random"
$X128 = "x128 -autostart-delay-random"
#$X128 = "x128 -80col -autostart-delay-random"
$XPLUS4 = "xplus4 -autostart-delay-random"
$MEGA65 = "xemu-xmega65"
$C1541 = "c1541"
$EXOMIZER = "exomizer/src/exomizer"
$ACME = "acme"
$commandline_quotemark = "'"
end
$PRINT_DISK_MAP = false # Set to true to print which blocks are allocated
# Typically none should be enabled.
$GENERALFLAGS = [
# 'CHECK_ERRORS' # Check for all runtime errors, making code bigger and slower
# 'SLOW', # Remove some optimizations for speed. This makes the terp ~100 bytes smaller.
# 'NODARKMODE', # Disables darkmode support. This makes the terp ~100 bytes smaller.
# 'VICE_TRACE', # Send the last instructions executed to Vice, to aid in debugging
# 'TRACE', # Save a trace of the last instructions executed, to aid in debugging
# 'COUNT_SWAPS', # Keep track of how many vmem block reads have been done.
# 'TIMING', # Store the lowest word of the jiffy clock in 0-->2 in the Z-code header
# 'UNDO', # Support UNDO (using REU)
]
# For a production build, none of these flags should be enabled.
$DEBUGFLAGS = [
# 'DEBUG', # This gives some debug capabilities, like informative error messages. It is automatically included if any other debug flags are used.
# 'VIEW_STACK_RECORDS',
# 'PRINTSPEED'
# 'BENCHMARK',
# 'VMEM_STRESS', # very slow but gives vmem a workout
# 'TRACE_FLOPPY',
# 'TRACE_VM',
# 'PRINT_SWAPS',
# 'TRACE_FLOPPY_VERBOSE',
# 'TRACE_PRINT_ARRAYS',
# 'TRACE_PROP',
# 'TRACE_READTEXT',
# 'TRACE_SHOW_DICT_ENTRIES',
# 'TRACE_TOKENISE',
# 'TRACE_HISTORY',
]
$CACHE_PAGES = 4 # Should normally be 2-8. Use 4 unless you have a good reason not to. One page will be added automatically if it would otherwise be wasted due to vmem alignment issues.
$CONFIG_TRACK = 1
MODE_P = 1
MODE_S1 = 2
MODE_S2 = 3
MODE_D2 = 4
MODE_D3 = 5
MODE_71 = 6
MODE_81 = 7
DISKNAME_BOOT = 128
DISKNAME_STORY = 129
DISKNAME_SAVE = 130
DISKNAME_DISK = 131
$BUILD_ID = Random.rand(0 .. 2**32-1)
$VMEM_BLOCKSIZE = 512
$ZEROBYTE = 0.chr
$EXECDIR = Dir.pwd
$SRCDIR = File.join(__dir__, 'asm')
$TEMPDIR = File.join(__dir__, 'temp')
Dir.mkdir($TEMPDIR) unless Dir.exist?($TEMPDIR)
$wrapper_labels_file = File.join($TEMPDIR, 'wrapper_labels.txt')
$wrapper_file = File.join($TEMPDIR, 'wrapper')
$labels_file = File.join($TEMPDIR, 'acme_labels.txt')
$loader_labels_file = File.join($TEMPDIR, 'acme_labels_loader.txt')
# $loader_pic_file = File.join($EXECDIR, 'loaderpic.kla')
$loader_file = File.join($TEMPDIR, 'loader')
$loader_zip_file = File.join($TEMPDIR, 'loader_zip')
$ozmoo_file = File.join($TEMPDIR, 'ozmoo')
$zip_file = File.join($TEMPDIR, 'ozmoo_zip')
$good_zip_file = File.join($TEMPDIR, 'ozmoo_zip_good')
$compmem_filename = File.join($TEMPDIR, 'compmem.tmp')
$universal_file = File.join($TEMPDIR, 'universal')
$config_filename = File.join($TEMPDIR, 'config.tmp')
$trinity_releases = {
"r11-s860509" => "fddd 2058 01",
"r12-s860926" => "fddd 2048 01",
"r15-s870628" => "fd8d 2048 01"
}
$lurkinghorror_releases = {
"r203-s870506" => "",
"r219-s870912" => "",
"r221-s870918" => ""
}
$beyondzork_releases = {
"r47-s870915" => "f347 14c2 00 a6 0b 64 23 57 62 97 80 84 a0 02 ca b2 13 44 d4 a5 8c 00 09 b2 11 24 50 9c 92 65 e5 7f 5d b1 b1 b1 b1 b1 b1 b1 b1 b1 b1 b1",
"r49-s870917" => "f2c0 14c2 00 a6 0b 64 23 57 62 97 80 84 a0 02 ca b2 13 44 d4 a5 8c 00 09 b2 11 24 50 9c 92 65 e5 7f 5d b1 b1 b1 b1 b1 b1 b1 b1 b1 b1 b1",
"r51-s870923" => "f2a8 14c2 00 a6 0b 64 23 57 62 97 80 84 a0 02 ca b2 13 44 d4 a5 8c 00 09 b2 11 24 50 9c 92 65 e5 7f 5d b1 b1 b1 b1 b1 b1 b1 b1 b1 b1 b1",
"r57-s871221" => "f384 14c2 00 a6 0b 64 23 57 62 97 80 84 a0 02 ca b2 13 44 d4 a5 8c 00 09 b2 11 24 50 9c 92 65 e5 7f 5d b1 b1 b1 b1 b1 b1 b1 b1 b1 b1 b1",
"r60-s880610" => "f2dc 14c2 00 a6 0b 64 23 57 62 97 80 84 a0 02 ca b2 13 44 d4 a5 8c 00 09 b2 11 24 50 9c 92 65 e5 7f 5d b1 b1 b1 b1 b1 b1 b1 b1 b1 b1 b1"
}
$d81interleave = [
# 0:No interleave
{},
# 1: 0,1, 4,5, 8,9, 12,13, ...
{ 1 => 4, 5 => 8, 9 => 12, 13 => 16, 17 => 20, 21 => 24, 25 => 28, 29 => 32, 33 => 36, 37 => 0,
3 => 6, 7 => 10, 11 => 14, 15 => 18, 19 => 22, 23 => 26, 27 => 30, 31 => 34, 35 => 38, 39 => 2
},
# 2: 0, 4, 8, 12, ...
{ 0 => 4, 4 => 8, 8 => 12, 12 => 16, 16 => 20, 20 => 24, 24 => 28, 28 => 32, 32 => 36, 36 => 1,
1 => 5, 5 => 9, 9 => 13, 13 => 17, 17 => 21, 21 => 25, 25 => 29, 29 => 33, 33 => 37, 37 => 2,
2 => 6, 6 => 10, 10 => 14, 14 => 18, 18 => 22, 22 => 26, 26 => 30, 30 => 34, 34 => 38, 38 => 3,
3 => 7, 7 => 11, 11 => 15, 15 => 19, 19 => 23, 23 => 27, 27 => 31, 31 => 35, 35 => 39
},
]
$i81 = $d81interleave[1] # Optimal scheme for MEGA65, as far as we can tell. File copying is not done in make.rb for other platforms.
class Disk_image
def base_initialize
@interleave = 1
@config_track = $CONFIG_TRACK
@skip_tracks = Array.new(@tracks)
offset = 0
@track_offset = @track_length.map {|len| k = offset; offset += len; k }
# puts "offset = #{@track_offset}"
@reserved_sectors = Array.new(@track_length.length, 0)
@config_track_map = []
@contents = Array.new(256 * @track_length.inject(0, :+), 0)
@storydata_start_track = 0
@storydata_end_track = 0
@storydata_blocks = 0
end
def calculate_initial_free_blocks
@free_blocks = @track_length.inject(0, :+) - @reserved_sectors.inject(0, :+)
puts "Free disk blocks at start: #{@free_blocks}" if $verbose
end
def free_blocks
@free_blocks
end
def interleave
@interleave
end
attr_accessor :interleave_scheme
# def interleave_scheme
# @interleave_scheme
# end
# def interleave_scheme = (interleave_scheme)
# @interleave_scheme = interleave_scheme
# end
def add_story_data(max_story_blocks:, add_at_end:)
max_story_blocks -= 1 if max_story_blocks % 2 != 0
story_data_length = $story_file_data.length - $story_file_cursor
num_sectors = [story_data_length / 256, max_story_blocks].min
first_story_track = 1
first_story_track_max_sectors = get_track_length(first_story_track) - get_reserved_sectors(first_story_track)
temp_sectors = num_sectors
if add_at_end then
@tracks.downto(1) do |track|
track_sectors = get_track_length(track) - get_reserved_sectors(track)
if temp_sectors > track_sectors then
temp_sectors -= track_sectors
else
first_story_track = track
first_story_track_max_sectors = temp_sectors
break
end
end
end
for track in 1 .. @tracks do
print "#{track}:" if $PRINT_DISK_MAP
if num_sectors > 0 then
reserved_sectors = get_reserved_sectors(track)
sector_count = get_track_length(track)
if track < first_story_track then
sector_count = reserved_sectors
elsif track == first_story_track
sector_count = first_story_track_max_sectors + reserved_sectors
elsif sector_count - reserved_sectors > num_sectors
sector_count = num_sectors + reserved_sectors
end
track_map = Array.new(sector_count, 0)
reserved_sectors.times do |i|
track_map[i] = 1
end
free_sectors_in_track = sector_count - reserved_sectors
last_story_sector = 0
# Find right sector.
# 1. Start at 0
# 2. Find next free sector
# 3. Decrease blocks to go. If < 0, we are done
# 4. Mark sector as used.
# 5. Add interleave, go back to 2
sector = 0
[free_sectors_in_track, num_sectors].min.times do
while track_map[sector] != 0
sector = (sector + 1) % sector_count
end
track_map[sector] = 1
allocate_sector(track, sector)
add_story_block(track, sector)
last_story_sector += 1
@free_blocks -= 1
num_sectors -= 1
@storydata_start_track = track if @storydata_start_track < 1
@storydata_end_track = track
@storydata_blocks += 1
sector = (sector + @interleave) % sector_count
end
@config_track_map.push(64 * reserved_sectors / 2 + last_story_sector)
else
@config_track_map.push 0
end # if num_sectors > 0
puts if $PRINT_DISK_MAP
end # for track
# puts num_sectors.to_s
add_directory()
@config_track_map = @config_track_map.reverse.drop_while{|i| i==0}.reverse # Drop trailing zero elements
@free_blocks
end
def config_track_map
@config_track_map
end
def set_config_data(data)
if !@is_boot_disk then
puts "ERROR: Tried to save config data on a non-boot disk."
exit 1
elsif !(data.is_a?(Array)) or data.length > 512 then
puts "ERROR: Config data array is not the right length."
exit 1
end
data[5] = @interleave
@contents[@track_offset[@config_track] * 256 .. @track_offset[@config_track] * 256 + data.length - 1] = data
end
def save
begin
diskimage_file = File.open(@diskimage_filename, "wb")
rescue
puts "ERROR: Can't open #{@diskimage_filename} for writing"
exit 1
end
diskimage_file.write @contents.pack("C*")
diskimage_file.close
end
def get_track_length(track)
@track_length[track]
end
def get_reserved_sectors(track)
@reserved_sectors[track]
end
def add_story_block(track, sector)
story_block_added = false
if $story_file_data.length > $story_file_cursor + 1
@contents[256 * (@track_offset[track] + sector) .. 256 * (@track_offset[track] + sector) + 255] =
$story_file_data[$story_file_cursor .. $story_file_cursor + 255].unpack("C*")
$story_file_cursor += 256
story_block_added = true
end
story_block_added
end
end # class Disk_image
class D64_image < Disk_image
def initialize(disk_title:, diskimage_filename:, is_boot_disk:, forty_tracks:)
puts "Creating disk image..." if $verbose
@disk_title = disk_title
@diskimage_filename = diskimage_filename
@is_boot_disk = is_boot_disk
@tracks = forty_tracks ? 40 : 35 # 35 or 40 are useful options
@track_length = Array.new(@tracks + 1) {|track|
track == 0 ? 0 :
track < 18 ? 21 :
track < 25 ? 19 :
track < 31 ? 18 :
17
}
# puts "Tracks: #{@track_length.to_s}"
base_initialize()
@interleave = 9
# NOTE: Blocks to skip can only be 0, 2, 4 or 6, or entire track.
@reserved_sectors[18] = 2 # 2: Skip BAM and 1 directory block, 19: Skip entire track
@reserved_sectors[@config_track] = 2 if @is_boot_disk and @config_track
calculate_initial_free_blocks()
# BAM
@track1800 = [
# $16500 = 91392 = 357 (18,0)
0x12,0x01, # track/sector
0x41, # DOS version
0x00, # unused
# <free sectors>,<0-7>,<8-15>,<16-?, remaining bits 0>
0x15,0xff,0xff,0x1f, # 16504, track 01 (21 sectors)
0x15,0xff,0xff,0x1f, # 16508, track 02
0x15,0xff,0xff,0x1f, # 1650c, track 03
0x15,0xff,0xff,0x1f, # 16510, track 04
0x15,0xff,0xff,0x1f, # 16514, track 05
0x15,0xff,0xff,0x1f, # 16518, track 06
0x15,0xff,0xff,0x1f, # 1651c, track 07
0x15,0xff,0xff,0x1f, # 16520, track 08
0x15,0xff,0xff,0x1f, # 16524, track 09
0x15,0xff,0xff,0x1f, # 16528, track 10
0x15,0xff,0xff,0x1f, # 1652c, track 11
0x15,0xff,0xff,0x1f, # 16530, track 12
0x15,0xff,0xff,0x1f, # 16534, track 13
0x15,0xff,0xff,0x1f, # 16538, track 14
0x15,0xff,0xff,0x1f, # 1653c, track 15
0x15,0xff,0xff,0x1f, # 16540, track 16
0x15,0xff,0xff,0x1f, # 16544, track 17
0x11,0xfc,0xff,0x07, # 16548, track 18 (19 sectors)
0x13,0xff,0xff,0x07, # 1654c, track 19
0x13,0xff,0xff,0x07, # 16550, track 20
0x13,0xff,0xff,0x07, # 16554, track 21
0x13,0xff,0xff,0x07, # 16558, track 22
0x13,0xff,0xff,0x07, # 1655c, track 23
0x13,0xff,0xff,0x07, # 16560, track 24
0x12,0xff,0xff,0x03, # 16564, track 25 (18 sectors)
0x12,0xff,0xff,0x03, # 16568, track 26
0x12,0xff,0xff,0x03, # 1656c, track 27
0x12,0xff,0xff,0x03, # 16570, track 28
0x12,0xff,0xff,0x03, # 16574, track 29
0x12,0xff,0xff,0x03, # 16578, track 30
0x11,0xff,0xff,0x01, # 1657c, track 31 (17 sectors)
0x11,0xff,0xff,0x01,0x11,0xff,0xff,0x01,
0x11,0xff,0xff,0x01,0x11,0xff,0xff,0x01,
0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0, # label (game name)
0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,
0xa0,0xa0,0x30,0x30,0xa0,0x32,0x41,0xa0,
0xa0,0xa0,0xa0,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x11,0xff,0xff,0x01,0x11,0xff,0xff,0x01,
0x11,0xff,0xff,0x01,0x11,0xff,0xff,0x01,
0x11,0xff,0xff,0x01,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
]
# Create a disk image. Return number of free blocks, or -1 for failure.
for track in 36 .. 40 do
@track1800[0xc0 + 4 * (track - 36) .. 0xc0 + 4 * (track - 36) + 3] = (track > @tracks ? [0,0,0,0] : [0x11,0xff,0xff,0x01])
end
# Set disk title
c64_title = name_to_c64(disk_title)
@track1800[0x90 .. 0x9f] = Array.new(0x10, 0xa0)
[c64_title.length, 0x10].min.times do |charno|
@track1800[0x90 + charno] = c64_title[charno].ord
end
if @is_boot_disk and @config_track then
allocate_sector(@config_track, 0)
allocate_sector(@config_track, 1)
end
@free_blocks
end # initialize
private
def allocate_sector(track, sector)
print "*" if $PRINT_DISK_MAP
index1 = 4 * track
index2 = 4 * track + 1 + (sector / 8)
if track > 35 then # Use SpeedDOS 40-track BAM layout
index1 += 0x30
index2 += 0x30
end
# adjust number of free sectors
@track1800[index1] -= 1
# allocate sector
index3 = 255 - 2**(sector % 8)
@track1800[index2] &= index3
end
def add_directory()
# Add disk info and BAM at 18:00
@contents[@track_offset[18] * 256 .. @track_offset[18] * 256 + 255] = @track1800
# Add directory at 18:01
@contents[@track_offset[18] * 256 + 256] = 0
@contents[@track_offset[18] * 256 + 257] = 0xff
end
end # class D64_image
class D71_image < Disk_image
def initialize(disk_title:, diskimage_filename:, is_boot_disk:)
puts "Creating disk image..." if $verbose
@disk_title = disk_title
@diskimage_filename = diskimage_filename
@is_boot_disk = is_boot_disk
@tracks = 70
@track_length = Array.new(@tracks + 1) {|track|
track == 0 ? 0 :
track < 18 ? 21 :
track < 25 ? 19 :
track < 31 ? 18 :
track < 36 ? 17 :
track < 53 ? 21 :
track < 60 ? 19 :
track < 66 ? 18 :
17
}
# puts "Tracks: #{@track_length.to_s}"
base_initialize()
@interleave = 5
# NOTE: Blocks to skip can only be 0, 2, 4 or 6, or entire track.
@reserved_sectors[18] = 2 # 2: Skip BAM and 1 directory block, 19: Skip entire track
@reserved_sectors[53] = 2 # 2: Skip BAM and 1 extra block (we can't skip just 1 block)
@reserved_sectors[@config_track] = 2 if @is_boot_disk and @config_track
calculate_initial_free_blocks()
# BAM
@track1800 = [
# $16500 = 91392 = 357 (18,0)
0x12,0x01, # track/sector
0x41, # DOS version
0x80, # $80 = Double-sided
# <free sectors>,<0-7>,<8-15>,<16-?, remaining bits 0>
0x15,0xff,0xff,0x1f, # 16504, track 01 (21 sectors)
0x15,0xff,0xff,0x1f, # 16508, track 02
0x15,0xff,0xff,0x1f, # 1650c, track 03
0x15,0xff,0xff,0x1f, # 16510, track 04
0x15,0xff,0xff,0x1f, # 16514, track 05
0x15,0xff,0xff,0x1f, # 16518, track 06
0x15,0xff,0xff,0x1f, # 1651c, track 07
0x15,0xff,0xff,0x1f, # 16520, track 08
0x15,0xff,0xff,0x1f, # 16524, track 09
0x15,0xff,0xff,0x1f, # 16528, track 10
0x15,0xff,0xff,0x1f, # 1652c, track 11
0x15,0xff,0xff,0x1f, # 16530, track 12
0x15,0xff,0xff,0x1f, # 16534, track 13
0x15,0xff,0xff,0x1f, # 16538, track 14
0x15,0xff,0xff,0x1f, # 1653c, track 15
0x15,0xff,0xff,0x1f, # 16540, track 16
0x15,0xff,0xff,0x1f, # 16544, track 17
0x11,0xfc,0xff,0x07, # 16548, track 18 (19 sectors)
0x13,0xff,0xff,0x07, # 1654c, track 19
0x13,0xff,0xff,0x07, # 16550, track 20
0x13,0xff,0xff,0x07, # 16554, track 21
0x13,0xff,0xff,0x07, # 16558, track 22
0x13,0xff,0xff,0x07, # 1655c, track 23
0x13,0xff,0xff,0x07, # 16560, track 24
0x12,0xff,0xff,0x03, # 16564, track 25 (18 sectors)
0x12,0xff,0xff,0x03, # 16568, track 26
0x12,0xff,0xff,0x03, # 1656c, track 27
0x12,0xff,0xff,0x03, # 16570, track 28
0x12,0xff,0xff,0x03, # 16574, track 29
0x12,0xff,0xff,0x03, # 16578, track 30
0x11,0xff,0xff,0x01, # 1657c, track 31 (17 sectors)
0x11,0xff,0xff,0x01, # track 32
0x11,0xff,0xff,0x01, # track 33
0x11,0xff,0xff,0x01, # track 34
0x11,0xff,0xff,0x01, # track 35
0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0, # label (game name)
0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,
0xa0,0xa0,0x30,0x30,0xa0,0x32,0x41,0xa0,
0xa0,0xa0,0xa0,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00, # -$dc
0x15,0x15,0x15, # $dd- (free sector count for track 36-70)
0x15,0x15,0x15,0x15,0x15,0x15,0x15,0x15,
0x15,0x15,0x15,0x15,0x15,0x15,0x11,0x13,
0x13,0x13,0x13,0x13,0x13,0x12,0x12,0x12,
0x12,0x12,0x12,0x11,0x11,0x11,0x11,0x11
]
@track5300 = [
# <0-7>,<8-15>,<16-?, remaining bits 0>
0xff,0xff,0x1f, # track 36 (21 sectors)
0xff,0xff,0x1f,
0xff,0xff,0x1f,
0xff,0xff,0x1f,
0xff,0xff,0x1f,
0xff,0xff,0x1f,
0xff,0xff,0x1f,
0xff,0xff,0x1f,
0xff,0xff,0x1f,
0xff,0xff,0x1f,
0xff,0xff,0x1f,
0xff,0xff,0x1f,
0xff,0xff,0x1f,
0xff,0xff,0x1f,
0xff,0xff,0x1f,
0xff,0xff,0x1f,
0xff,0xff,0x1f,
0xfc,0xff,0x07, # track 53 (19 sectors, 2 used)
0xff,0xff,0x07, # track 54 (19 sectors)
0xff,0xff,0x07,
0xff,0xff,0x07,
0xff,0xff,0x07,
0xff,0xff,0x07,
0xff,0xff,0x07,
0xff,0xff,0x03, # track 60 (18 sectors)
0xff,0xff,0x03,
0xff,0xff,0x03,
0xff,0xff,0x03,
0xff,0xff,0x03,
0xff,0xff,0x03,
0xff,0xff,0x01, # track 66 (17 sectors)
0xff,0xff,0x01,
0xff,0xff,0x01,
0xff,0xff,0x01,
0xff,0xff,0x01,
0x00,0x00,0x00,0x00,0x00,0x00,0x00, # $69-$6f
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, #$70-
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, #$80-
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, #$90-
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, #$a0-
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, #$b0-
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, #$c0-
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, #$d0-
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, #$e0-
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, #$f0-
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
]
# Create a disk image. Return number of free blocks, or -1 for failure.
# for track in 36 .. 40 do
# @track1800[0xc0 + 4 * (track - 36) .. 0xc0 + 4 * (track - 36) + 3] = (track > @tracks ? [0,0,0,0] : [0x11,0xff,0xff,0x01])
# end
# Set disk title
c64_title = name_to_c64(disk_title)
@track1800[0x90 .. 0x9f] = Array.new(0x10, 0xa0)
[c64_title.length, 0x10].min.times do |charno|
@track1800[0x90 + charno] = c64_title[charno].ord
end
if @is_boot_disk and @config_track then
allocate_sector(@config_track, 0)
allocate_sector(@config_track, 1)
end
@free_blocks
end # initialize
private
def allocate_sector(track, sector)
print "*" if $PRINT_DISK_MAP
if track > 35 then # BAM is (mostly) in sector 53:0
index1 = 0xdd + track - 36
index2 = 3 * (track - 36) + (sector / 8)
# adjust number of free sectors
@track1800[index1] -= 1
# allocate sector
index3 = 255 - 2**(sector % 8)
@track5300[index2] &= index3
else
index1 = 4 * track
index2 = 4 * track + 1 + (sector / 8)
if track > 35 then # BAM is (mostly) in sector 53:0
index1 += 0x30
index2 += 0x30
end
# adjust number of free sectors
@track1800[index1] -= 1
# allocate sector
index3 = 255 - 2**(sector % 8)
@track1800[index2] &= index3
end
end
def add_directory()
# Add disk info and BAM at 18:00
@contents[@track_offset[18] * 256 .. @track_offset[18] * 256 + 255] = @track1800
# Add directory at 18:01
@contents[@track_offset[18] * 256 + 256] = 0
@contents[@track_offset[18] * 256 + 257] = 0xff
# Add BAM 53:00
@contents[@track_offset[53] * 256 .. @track_offset[53] * 256 + 255] = @track5300
end
end # class D71_image
class D81_image < Disk_image
def initialize(disk_title:, diskimage_filename:)
puts "Creating disk image..." if $verbose
@disk_title = disk_title
@diskimage_filename = diskimage_filename
@is_boot_disk = true
@tracks = 80
@track_length = Array.new(@tracks + 1, 40)
@track_length[0] = 0
@add_to_dir = []
base_initialize()
# NOTE: Blocks to skip can only be 0, 2, 4 or 6, or entire track.
@reserved_sectors[40] = 40 # 4: Skip BAM and 1 directory block, 6: Skip BAM and 3 directory blocks, 40: Skip entire track
if @config_track
@reserved_sectors[@config_track] = 2
end
calculate_initial_free_blocks()
# BAM
@track4000 = [
# $16500 = 91392 = 357 (18,0)
0x28, 0x03, # track/sector of first directory sector
0x44, # DOS version
0x00, # Not used, don't alter value
0x4F, 0x5A, 0x4D, 0x4F, 0x4F, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, # Disk name
0xA0, 0xA0, # Not used, don't alter value
0x31, 0x41, # Disk ID
0xA0, # Not used, don't alter value
0x33, # DOS version
0x44, # Disk version
0xA0, 0xA0 # Not used, don't alter value
]
@track4001 = [
0x28,0x02, # track/sector of next BAM sector
0x44, # Version#
0xBB, # One's complement of version#
0x31,0x41, # Disk ID (same as in 40:00)
0xC0, # I/O byte
0x00, # Auto-boot-loader flags
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, # Reserved for future use
0x28,0xFF,0xFF,0xFF,0xFF,0xFF, # Track 1
0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF, # Track 2-4
0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF, # Track 5-8
0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF, # Track 9-12
0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF, # Track 13-16
0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF, # Track 17-20
0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF, # Track 21-24
0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF, # Track 25-28
0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF, # Track 29-32
0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF, # Track 33-36
0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x24,0xF0,0xFF,0xFF,0xFF,0xFF, # Track 37-40
# Sector 40:02
0x00,0xFF, # track/sector of next BAM sector
0x44, # Version#
0xBB, # One's complement of version#
0x31,0x41, # Disk ID (same as in 40:00)
0xC0, # I/O byte
0x00, # Auto-boot-loader flags
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, # Reserved for future use
0x28,0xFF,0xFF,0xFF,0xFF,0xFF, # Track 41
0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF, # Track 42-44
0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF, # Track 45-48
0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF, # Track 49-52
0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF, # Track 53-56
0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF, # Track 57-60
0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF, # Track 61-64
0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF, # Track 65-68
0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF, # Track 69-72
0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF, # Track 73-76
0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF,0x28,0xFF,0xFF,0xFF,0xFF,0xFF # Track 77-80
]
# Add BAM at 40:01 and 40:02
@contents[(@track_offset[40] + 1) * 256 .. (@track_offset[40] + 1) * 256 + @track4001.length - 1] = @track4001
# Create a disk image. Return number of free blocks, or -1 for failure.
# Set disk title
c64_title = name_to_c64(disk_title)
@track4000[0x04 .. 0x13] = Array.new(0x10, 0xa0)
[c64_title.length, 0x10].min.times do |charno|
@track4000[0x04 + charno] = c64_title[charno].ord
end
if @config_track
allocate_sector(@config_track, 0)
allocate_sector(@config_track, 1)
end
@free_blocks
end # initialize
def create_story_partition
if @storydata_start_track > 0 and @storydata_end_track >= @storydata_start_track
sector = @contents[(@track_offset[40] + 3) * 256 .. (@track_offset[40] + 3) * 256 + 255]
@storydata_start_track -= 1 if @config_track == @storydata_start_track - 1
@storydata_end_track += 1 if @config_track == @storydata_end_track + 1
allocate_track(@storydata_end_track)
allocate_track(@config_track)
if @storydata_start_track < 40 and @storydata_end_track > 40
return false unless create_a_partition(sector, @storydata_start_track, 39, 'data-a') == true
@contents[(@track_offset[40] + 3) * 256 .. (@track_offset[40] + 3) * 256 + 255] = sector
return false unless create_a_partition(sector, 41, @storydata_end_track, 'data-b') == true
@contents[(@track_offset[40] + 3) * 256 .. (@track_offset[40] + 3) * 256 + 255] = sector
else
return false unless create_a_partition(sector, @storydata_start_track, @storydata_end_track, 'data') == true
@contents[(@track_offset[40] + 3) * 256 .. (@track_offset[40] + 3) * 256 + 255] = sector
end
if @config_track < @storydata_start_track or @config_track > @storydata_end_track
return false unless create_a_partition(sector, @config_track, @config_track, 'cfg') == true
@contents[(@track_offset[40] + 3) * 256 .. (@track_offset[40] + 3) * 256 + 255] = sector
end
true
else
false
end
end
def add_file(filename, filecontents, last_sector = nil) # Returns last sector used
sector_count = 0
last_sector_used = nil
if filecontents == nil or filecontents.length == 0
start_sector = [0,0]
last_sector_used = start_sector
else
# Find first free sector as close as possible to the last sector used by the last file
start_sector = find_free_file_start_sector(last_sector)
last_sector_used = start_sector
if start_sector == nil
puts "ERROR: No free blocks left on disk."
exit 1
end
sector_count += 1
this_sector = start_sector
while filecontents.length > 254
next_sector = find_next_free_sector(this_sector[0], this_sector[1])
if next_sector == nil
puts "ERROR: No free blocks left on disk."
exit 1
end
last_sector_used = next_sector
sector_count += 1
block_contents = next_sector.pack("CC") + filecontents[0 .. 253]
filecontents = filecontents[254 .. filecontents.size - 1]
@contents[256 * (@track_offset[this_sector[0]] + this_sector[1]) ..
256 * (@track_offset[this_sector[0]] + this_sector[1]) + 255] =
block_contents.unpack("C*")
this_sector = next_sector
end
block_contents = [0, filecontents.length + 2 - 1].pack("CC") + filecontents + Array.new(254 - filecontents.length).fill(0).pack("c*")
@contents[256 * (@track_offset[this_sector[0]] + this_sector[1]) ..
256 * (@track_offset[this_sector[0]] + this_sector[1]) + 255] =
block_contents.unpack("C*")
end
# Add file to directory
dir_entry = ([0x81] + start_sector).pack("CCC") +
name_to_c64(filename).ljust(16, 0xa0.chr) +
"".ljust(9, 0.chr) +
[sector_count % 256, sector_count / 256].pack("CC")
@add_to_dir.push dir_entry
return last_sector_used
end
private
def allocate_sector(track, sector)
print "*" if $PRINT_DISK_MAP
index1 = (track > 40 ? 0x100: 0) + 0x10 + 6 * ((track - 1) % 40)
index2 = index1 + 1 + (sector / 8)
# adjust number of free sectors
free = @contents[(@track_offset[40] + 1) * 256 + index1]
if free < 1 or free > 40
puts "BAD FREE TRACK SPACE: #{track}, #{sector}"
end
@contents[(@track_offset[40] + 1) * 256 + index1] = free - 1
# allocate sector
index3 = 255 - 2**(sector % 8)
@contents[(@track_offset[40] + 1) * 256 + index2] &= index3
end
def sector_allocated?(track, sector)
index1 = (track > 40 ? 0x100: 0) + 0x10 + 6 * ((track - 1) % 40)
index2 = index1 + 1 + (sector / 8)
index3 = 2**(sector % 8)
# is sector allocated?
return @contents[(@track_offset[40] + 1) * 256 + index2] & index3 == 0
end
def find_free_file_start_sector(last_sector = nil)
if last_sector
return find_next_free_sector(last_sector[0], last_sector[1])
else
1.upto 40 do |t|
40.times do |s|
unless t > 39 or sector_allocated?(40 - t, s)
allocate_sector(40 - t, s)
return [40 - t, s]
end
unless sector_allocated?(40 + t, s)
allocate_sector(40 + t, s)
return [40 + t, s]
end
end
end
end
return nil
end
def find_next_free_sector(track, sector)
start_track = track
tried_track_1 = nil
tried_track_80 = nil
tried_sectors = []
if interleave_scheme && interleave_scheme.has_key?(sector)
next_sector = interleave_scheme[sector]
else
next_sector = (sector + 1) % 40
end
loop do
unless sector_allocated?(track, next_sector)
allocate_sector(track, next_sector)
return [track, next_sector]
end
tried_sectors.push next_sector unless tried_sectors.include? next_sector
if tried_sectors.length > 39
# This track is full, go to next
tried_track_1 = true if track == 1
tried_track_80 = true if track == 80
return nil if tried_track_1 and tried_track_80 # No free sectors, fail!
# Choose a track to try next
if track < 40
if track > 1
track -= 1
else
track = 41
end
else
if track < 80
track += 1
else
track = 39
end
end
next_sector = (sector + 8)
next_sector = next_sector - (next_sector % 2)
next_sector = next_sector % 40
else
next_sector = (next_sector > 38) ? 0 : next_sector + 1
end
end
end
def add_directory()
# Add disk info at 40:00
@contents[@track_offset[40] * 256 .. @track_offset[40] * 256 + @track4000.length - 1] = @track4000
# Add directory at 40:03
@contents[(@track_offset[40] + 3) * 256] = 0
@contents[(@track_offset[40] + 3) * 256 + 1] = 0xff
add_files_to_dir(3,2)
end
def add_files_to_dir(sector, entry)
unless @add_to_dir.empty?
block_data = @contents[(@track_offset[40] + sector) * 256 .. (@track_offset[40] + sector) * 256 + 255]
block_data[1] = 0xff
while !@add_to_dir.empty? do
while entry < 8 and block_data[0x20 * entry + 2] > 0
entry += 1
end
if entry > 7
block_data[0] = 40
block_data[1] = sector + 1
allocate_sector(40, sector + 1)
add_files_to_dir(sector + 1, 0)
else
dir_entry = @add_to_dir[0]
@add_to_dir = @add_to_dir.drop(1)
block_data[0x20 * entry + 2 .. 0x20 * entry + 0x1f] = dir_entry.unpack("C*")
end
end
@contents[(@track_offset[40] + sector) * 256 .. (@track_offset[40] + sector) * 256 + 255] = block_data
@add_to_dir = []
end
end
def create_a_partition(sector, start_track, end_track, name)
entry = 1
while entry < 8 and sector[0x20 * entry + 2] > 0
entry += 1
end
return false if entry > 7
entrybase = 0x20 * entry
sector[entrybase + 2] = 0x85 # CBM type ( = partition)
sector[entrybase + 3] = start_track
sector[entrybase + 4] = 0 # Start sector
c64_title = name_to_c64(name)
sector[entrybase + 0x5 .. entrybase + 0x14] = Array.new(0x10, 0xa0)
[c64_title.length, 0x10].min.times do |charno|
sector[entrybase + 0x5 + charno] = c64_title[charno].ord
end
sector[entrybase + 0x15 .. entrybase + 0x1d] = Array.new(9, 0)
part_size = (end_track - start_track + 1) * 40
sector[entrybase + 0x1e] = part_size % 256
sector[entrybase + 0x1f] = part_size / 256
true
end
def allocate_track(track)
index1 = (track > 40 ? 0x100: 0) + 0x10 + 6 * ((track - 1) % 40)
@contents[(@track_offset[40] + 1) * 256 + index1 .. (@track_offset[40] + 1) * 256 + index1 + 5] = Array.new(6, 0)
end
end # class D81_image
################################## END Disk image classes
def filename_to_title(name, remove_the_if_longer_than)
# Convert camel case and underscore to spaces. Remove "The" or "A" at beginning if the name gets too long.
title = name.dup
camel_case = title =~ /[a-z]/ and title =~ /[A-Z]/ and title !~ / |_/
if camel_case then
title.gsub!(/([a-z])([A-Z])/,'\1 \2')
title.gsub!(/A([A-Z])/,'A \1')
end
title.gsub!(/_+/," ")
title.gsub!(/(^ +)|( +)$/,"")
if remove_the_if_longer_than
title.gsub!(/^(the|a) (.*)$/i,'\2') if title.length > remove_the_if_longer_than
end