-
Notifications
You must be signed in to change notification settings - Fork 0
/
GRABBER.ELPC
1014 lines (807 loc) · 21.7 KB
/
GRABBER.ELPC
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
'----
.docs
'----
' Grabber Tool - ported to Eleven (for easier maintenance)
' ============
'
' Usage:
' -----
' - Press 'space' key on top-left point
' - Then use cursor keys to move to bottom-right point & press 'space'
' - Press '-' and '+' keys to move between previous and next frames
' - Press 'c' to redraw current frame
' - Press 'y' to yank/copy a selected region
' - Press 'p' to paste a selected region to current cursor location
' - Press 'e' to edit current frame
' - Press 'd' to delete the current frame
' - Press 'l' then a frame# to load that frame
' - Press 'x' to exit program
' - F1 = load char+color .bin file
' - F3 = save char+color .bin file
' - F5 = save optimized+repaired .bin file
' - F7 = edit hit boxes
#output "grabber"
' Char+Color File Format (F1/F3 keys)
' ======================
' WORD: prog-address (ignored)
' WORD: size of data (including this WORD and onwards)
' BYTE: # of frames
'
' FRAME #0
' --------
' BYTE: x
' BYTE: y
' BYTE: w
' BYTE: h
' DWORD: head box (x1,y1,x2,y2)
' DWORD: torso box (x1,y1,x2,y2)
' DWORD: feet box (x1,y1,x2,y2)
' DWORD: attack box (x1,y1,x2,y2)
' BYTE[w*h]: char data
' BYTE[w*h]: color data
'
' FRAME #1
' --------
' (as before...)
'
' FRAME #n
' --------
' (as before...)
' Color-only File Format (F5 key)
' ======================
' WORD: prog-address (ignored)
' WORD: size of data (including this WORD and onwards)
' BYTE: # of frames
'
' FRAME #0
' --------
' BYTE: x
' BYTE: y
' BYTE: w
' BYTE: h
' DWORD: head box (x1,y1,x2,y2)
' DWORD: torso box (x1,y1,x2,y2)
' DWORD: feet box (x1,y1,x2,y2)
' DWORD: attack box (x1,y1,x2,y2)
' BYTE[w*h]: color data
'
' FRAME #1
' --------
' (as before...)
'
' FRAME #n
' --------
' (as before...)
'--------
.declares
'--------
#declare clr_line_right$ = chr$(27)+"q" ' old cl$
#declare current_frame ' old ff
#declare x, y ' cursor position
#declare ptr ' pointer to data bytes in memory
#declare frame_count
#declare frmidx
#declare bytes_used ' old l
#declare frmw, frmh
#declare start_char, start_color, end_char, end_color
#declare startx, starty, endx, endy
#declare curr_frame
#declare src_char_ptr, src_clr_ptr
#declare a$, xidx, yidx
#declare dest_char_ptr, dest_clr_ptr
#declare fname$
#declare cval
#declare start_ptr, end_ptr, curr_ptr, src_ptr, dest_ptr, sz, k, ln
#declare b(50,3) ' hitboxes
#declare x1, y1, x2, y2
#declare hb_sel = 0, hb_mode, idx
#declare clipboard_char&(80*50)
#declare clipboard_clr&(80*50)
#declare clipw, cliph
#define STORE_START_POS = 0
#define STORE_END_POS = 1
#declare store_state ' are we storing start/end pos char/colour details
#declare new_frame_flag
#define KEY_UP = "{x91}"
#define KEY_DOWN = "{x11}"
#define KEY_LEFT = "{x9D}"
#define KEY_RIGHT = "{x1D}"
#define KEY_F1 = "{x85}"
#define KEY_F3 = "{x86}"
#define KEY_F4 = "{x8A}"
#define KEY_F5 = "{x87}"
#define KEY_F7 = "{x88}"
#define KEY_F8 = "{x8C}"
#define KEY_ESC = chr$(27)
#define KEY_REV_ON = "{x12}"
#define KEY_REV_OFF = "{x92}"
#define KEY_RETURN = chr$(13)
#define OP_COPY = 0
#define OP_MIX = 1
#define OP_SWAP = 2
#define OP_FILL = 3
#define HB_MODE_BROWSE = 0
#define HB_MODE_SEL_COORD1 = 1
#define HB_MODE_SEL_COORD2 = 2
#define HB_MODE_COMPLETE = 3
.offsets
#define OFFSET_DATA_SIZE = 0
#define OFFSET_NUM_FRAMES = 2
#define OFFSET_FRAME0 = 3
#define FRM_OFFSET_X = 0
#define FRM_OFFSET_Y = 1
#define FRM_OFFSET_W = 2
#define FRM_OFFSET_H = 3
#define FRM_OFFSET_HITBOXES = 4
#define FRM_OFFSET_HB_HEAD = 4
#define FRM_OFFSET_HB_TORSO = 8
#define FRM_OFFSET_HB_FEET = 12
#define FRM_OFFSET_HB_ATTACK = 16
#define FRM_OFFSET_DATA = 20
#declare bx_offs(3)
bx_offs(0) = FRM_OFFSET_HB_HEAD
bx_offs(1) = FRM_OFFSET_HB_TORSO
bx_offs(2) = FRM_OFFSET_HB_FEET
bx_offs(3) = FRM_OFFSET_HB_ATTACK
'----
.main
'----
key off
poke $d020, 11, 14
gosub init_vars
gosub check_magic_signature
gosub check_edit_flag
gosub locate_next_free_byte
gosub draw_footer
do while 1
gosub store_state_info
gosub draw_cursor
gosub get_user_input
gosub show_coords
loop
'-----------
.show_coords
'-----------
cursor 0, 49
print clr_line_right$;
if store_state = STORE_START_POS then begin
print chr$(27)+"qx=";x;", y=";y;
bend
if store_state = STORE_END_POS then begin
print chr$(27)+"qx=";startx;", y=";starty;
print ", w=";x-startx+1;", h=";y-starty+1;
bend
print clr_line_right$;
return
'-----------
.enter_coord
'-----------
do while 1
gosub store_state_info
gosub draw_cursor
get key a$
if a$ <> KEY_RETURN then gosub restore_char_under_cursor
if a$ = KEY_LEFT and x > 0 then x = x - 1
if a$ = KEY_RIGHT and x < 79 then x = x + 1
if a$ = KEY_UP and y > 0 then y = y - 1
if a$ = KEY_DOWN and y < 49 then y = y + 1
if a$=KEY_RETURN then exit
loop
return
'--------------
.get_user_input
'--------------
getkey a$
if a$ <> " " then gosub restore_char_under_cursor
if a$ = KEY_LEFT and x > 0 then x = x - 1
if a$ = KEY_RIGHT and x < 79 then x = x + 1
if a$ = KEY_UP and y > 0 then y = y - 1
if a$ = KEY_DOWN and y < 49 then y = y + 1
if a$ = "d" then gosub delete_frame
if a$ = "y" then gosub yank_selection
if a$ = "p" then gosub paste
if a$ = "c" then begin
print "{x93}";
curr_frame = 0
gosub draw_curr_frame
bend
if a$="-" and curr_frame > 0 then begin
curr_frame = curr_frame - 1
gosub draw_curr_frame
bend
if a$="=" and curr_frame < peek($50002)-1 then begin
curr_frame = curr_frame + 1
gosub draw_curr_frame
bend
if a$=" " then begin
store_state = store_state + 1
if store_state = 2 then begin
gosub save_new_frame_to_memory
end
bend
bend
if a$="l" then gosub load_frame
if a$="x" then begin
cursor 0,0
key on
end
bend
if a$="e" then begin
cursor 0,40
poke $5fffc, 1 ' edit flag on
poke $5fffd, curr_frame
key on
end
bend
if a$ = KEY_F1 then gosub load_bin
if a$ = KEY_F3 then gosub save_bin
if a$ = KEY_F5 then gosub save_optimised
if a$ = KEY_F7 then gosub edit_hit_boxes
return
'--------------
.edit_hit_boxes
'--------------
hb_mode = HB_MODE_BROWSE
do while 1
gosub show_hitbox_table
gosub draw_hitboxes
gosub HB_get_user_input
if a$="x" or a$=KEY_ESC or a$=KEY_F7 then begin
print chr$(147);
gosub draw_curr_frame
exit
bend
loop
return
#define CHAR_BOX_TL = 112
#define CHAR_BOX_TR = 110
#define CHAR_BOX_BL = 109
#define CHAR_BOX_BR = 125
#define CHAR_HORZ = 64
#define CHAR_VERT = 93
#define CHAR_SPACE = 32
'---------
.draw_char
'---------
if peek($40800 + x + y * 80) <> CHAR_SPACE then begin
k = k + 128
bend:else begin
poke $ff80000 + x + y * 80, 1
bend
poke $40800 + x + y * 80, k
return
'-------------
.draw_hitboxes
'-------------
gosub draw_curr_frame
gosub get_curr_frame_ptr
for idx = 0 to 3
x1 = peek(ptr + bx_offs(idx))
y1 = peek(ptr + bx_offs(idx) + 1)
x2 = peek(ptr + bx_offs(idx) + 2)
y2 = peek(ptr + bx_offs(idx) + 3)
if not (x1=0 and y1=0 and x2=0 and y2=0) then begin
' draw corners
' ------------
x = x1 : y = y1 : k = CHAR_BOX_TL : gosub draw_char
x = x2 : y = y1 : k = CHAR_BOX_TR : gosub draw_char
x = x1 : y = y2 : k = CHAR_BOX_BL : gosub draw_char
x = x2 : y = y2 : k = CHAR_BOX_BR : gosub draw_char
' draw horizontals
' ----------------
for x = x1+1 to x2-1
y = y1 : k = CHAR_HORZ : gosub draw_char
y = y2 : k = CHAR_HORZ : gosub draw_char
next x
' draw verticals
' --------------
for y = y1+1 to y2-1
x = x1 : k = CHAR_VERT : gosub draw_char
x = x2 : k = CHAR_VERT : gosub draw_char
next y
bend
next idx
return
'-----------------
.show_hitbox_table
'-----------------
gosub get_curr_frame_ptr
curr_ptr = ptr
if hb_sel = 0 then print KEY_REV_ON;:else print KEY_REV_OFF;
cursor 40,40:print KEY_ESC;"q head: ";
k = FRM_OFFSET_HB_HEAD:gosub show_hitbox_coords
if hb_sel = 1 then print KEY_REV_ON;:else print KEY_REV_OFF;
cursor 40,41:print KEY_ESC;"q torso: ";
k = FRM_OFFSET_HB_TORSO:gosub show_hitbox_coords
if hb_sel = 2 then print KEY_REV_ON;:else print KEY_REV_OFF;
cursor 40,42:print KEY_ESC;"q feet: ";
k = FRM_OFFSET_HB_FEET:gosub show_hitbox_coords
if hb_sel = 3 then print KEY_REV_ON;:else print KEY_REV_OFF;
cursor 40,43:print KEY_ESC;"qattack: ";
k = FRM_OFFSET_HB_ATTACK:gosub show_hitbox_coords
print KEY_REV_OFF;
gosub get_selected_coords
return
'--------------------------
.get_selected_offset_into_k
'--------------------------
if hb_sel = 0 then k = FRM_OFFSET_HB_HEAD
if hb_sel = 1 then k = FRM_OFFSET_HB_TORSO
if hb_sel = 2 then k = FRM_OFFSET_HB_FEET
if hb_sel = 3 then k = FRM_OFFSET_HB_ATTACK
return
'-------------------
.get_selected_coords
'-------------------
gosub get_selected_offset_into_k
gosub peek_selected_coords_into_x1y1x2y2
return
'-----------------
.HB_get_user_input
'-----------------
get key a$
if a$=KEY_UP and hb_sel > 0 then hb_sel = hb_sel - 1
if a$=KEY_DOWN and hb_sel < 3 then hb_sel = hb_sel + 1
if a$="-" and curr_frame > 0 then begin
curr_frame = curr_frame - 1
gosub draw_curr_frame
bend
if a$="=" and curr_frame < peek($50002)-1 then begin
curr_frame = curr_frame + 1
gosub draw_curr_frame
bend
if a$=KEY_RETURN then begin
gosub get_selected_coords_into_x1y1x2y2
gosub get_selected_offset_into_k
poke curr_ptr + k , x1
poke curr_ptr + k + 1, y1
poke curr_ptr + k + 2, x2
poke curr_ptr + k + 3, y2
bend
return
'---------------------------------
.get_selected_coords_into_x1y1x2y2
'---------------------------------
' coord1
x = x1 : y = y1
store_state = STORE_START_POS
gosub enter_coord
x1 = x
y1 = y
' coord2
store_state = STORE_END_POS
gosub enter_coord
x2 = x
y2 = y
poke $40800 + startx + starty * 80, start_char
poke $ff80000 + startx + starty * 80, start_color
poke $40800 + endx + endy * 80, end_char
poke $ff80000 + endx + endy * 80, end_color
return
'----------------------------------
.peek_selected_coords_into_x1y1x2y2
'----------------------------------
x1 = peek(curr_ptr + k)
y1 = peek(curr_ptr + k + 1)
x2 = peek(curr_ptr + k + 2)
y2 = peek(curr_ptr + k + 3)
return
'------------------
.show_hitbox_coords
'------------------
gosub peek_selected_coords_into_x1y1x2y2
print x1;",";y1;",";x2;",";y2;
return
'--------
.load_bin
'--------
input "load name: ";fname$
if fname$ = "" then return
bload (fname$),p($50000)
' gosub one_off_repair
return
'--------------
.one_off_repair
'--------------
' inject spaces where needed
src_ptr = $42000
dest_ptr = $50000
frame_count = peek(src_ptr)
poke dest_ptr + OFFSET_NUM_FRAMES, frame_count
src_ptr = src_ptr + 1
dest_ptr = dest_ptr + OFFSET_FRAME0
sz = OFFSET_FRAME0
for k = 0 to frame_count - 1
poke dest_ptr + FRM_OFFSET_X, peek(src_ptr)
src_ptr = src_ptr + 1
poke dest_ptr + FRM_OFFSET_Y, peek(src_ptr)
src_ptr = src_ptr + 1
frmw = peek(src_ptr)
poke dest_ptr + FRM_OFFSET_W, frmw
src_ptr = src_ptr + 1
frmh = peek(src_ptr)
poke dest_ptr + FRM_OFFSET_H, frmh
src_ptr = src_ptr + 1
ln = FRM_OFFSET_DATA - FRM_OFFSET_HITBOXES
edma OP_FILL, ln, 0, dest_ptr + FRM_OFFSET_HITBOXES
ln = frmw * frmh * 2
edma OP_COPY, ln, src_ptr, dest_ptr + FRM_OFFSET_DATA
src_ptr = src_ptr + ln
dest_ptr = dest_ptr + FRM_OFFSET_DATA + ln
sz = sz + FRM_OFFSET_DATA + ln
next k
dest_ptr = $50000
wpoke dest_ptr + OFFSET_DATA_SIZE, sz
return
'--------
.save_bin
'--------
input "save name: ";fname$
if fname$ = "" then return
ptr = $50000 + wpeek($50000 + OFFSET_DATA_SIZE)
delete (fname$)
bsave (fname$),p($50000) to p(ptr)
return
'-------------------------------------
.calculate_optimised_data_size_into_sz
'-------------------------------------
sz = wpeek($50000 + OFFSET_DATA_SIZE)
ptr = $50000 + OFFSET_FRAME0
for k = 0 to frame_count - 1
frmw = peek(ptr + FRM_OFFSET_W)
frmh = peek(ptr + FRM_OFFSET_H)
sz = sz - frmw * frmh
ptr = ptr + FRM_OFFSET_DATA + frmw * frmh * 2
next k
return
'--------------
.save_optimised
'--------------
input "save name (optimised): ";fname$
if fname$ = "" then return
delete (fname$)
dopen #2,(fname$ + ",p"),w,u8
print #2, chr$(1);
print #2, chr$(2); ' dummy address
gosub calculate_optimised_data_size_into_sz
print #2, chr$(mod(sz, 256));
print #2, chr$(int(sz / 256));
print #2, chr$(frame_count);
ptr = $50000 + OFFSET_FRAME0
for frmidx = 0 to frame_count - 1
x = peek(ptr + FRM_OFFSET_X)
y = peek(ptr + FRM_OFFSET_Y)
frmw = peek(ptr + FRM_OFFSET_W)
frmh = peek(ptr + FRM_OFFSET_H)
print #2, chr$(x);chr$(y);chr$(frmw);chr$(frmh);
for k=0 to 15
print #2, chr$(peek(ptr + FRM_OFFSET_HITBOXES + k));
next k
src_char_ptr = ptr + FRM_OFFSET_DATA
src_clr_ptr = ptr + FRM_OFFSET_DATA + frmw * frmh
for k = 0 to frmw * frmh - 1
cval = peek(src_clr_ptr + k)
if peek(src_char_ptr + k) = 32 then begin
cval = $ff
bend
print #2, chr$(cval);
next k
ptr = ptr + FRM_OFFSET_DATA + frmw * frmh * 2
next frmidx
dclose #2
return
'------------------------
.save_new_frame_to_memory
'------------------------
poke $40800 + startx + starty * 80, start_char
poke $ff80000 + startx + starty * 80, start_color
poke $40800 + endx + endy * 80, end_char
poke $ff80000 + endx + endy * 80, end_color
frame_count = peek($50000 + OFFSET_NUM_FRAMES)
gosub locate_next_free_byte
ptr = $50000 + bytes_used
new_frame_flag = 1
gosub save_frame_to_memory_at_ptr
return
'---------------------------
.save_frame_to_memory_at_ptr
'---------------------------
poke ptr + FRM_OFFSET_X, startx
poke ptr + FRM_OFFSET_Y, starty
poke ptr + FRM_OFFSET_W, x - startx + 1
poke ptr + FRM_OFFSET_H, y - starty + 1
if new_frame_flag then begin
ln = FRM_OFFSET_DATA - FRM_OFFSET_HITBOXES
edma OP_FILL, ln, 0, ptr + FRM_OFFSET_HITBOXES
bend
ptr = ptr + FRM_OFFSET_DATA
for yidx = starty to y
for xidx = startx to x
poke ptr, peek($40800 + xidx + yidx * 80)
ptr = ptr + 1
next xidx
next yidx
for yidx = starty to y
for xidx = startx to x
poke ptr, peek($ff80000 + xidx + yidx * 80)
ptr = ptr + 1
next xidx
next yidx
if new_frame_flag then begin
wpoke $50000 + OFFSET_DATA_SIZE, ptr - $50000
poke $50000 + OFFSET_NUM_FRAMES, frame_count + 1
bend
cursor 0,49
print clr_line_right$;"frame count=";peek($50000 + OFFSET_NUM_FRAMES);
print ", next-free=$";hex$(ptr);
cursor 0,0
new_frame_flag = 0
return
'----------
.load_frame
'----------
print "{x13}";clr_line_right$;
input "frame#";curr_frame
gosub draw_curr_frame
return
'------------
.delete_frame
'------------
gosub get_end_ptr
end_ptr = ptr
' decrement frame count
frame_count = frame_count - 1
poke $50000 + OFFSET_NUM_FRAMES, frame_count
gosub delete_frame_size_from_total
if curr_frame = frame_count then begin
curr_frame = curr_frame - 1
bend : else begin
gosub shift_remaining_frames_along
bend
gosub draw_curr_frame
return
'----------------------------
.delete_frame_size_from_total
'----------------------------
gosub get_curr_frame_ptr
curr_ptr = ptr
frmw = peek(curr_ptr + FRM_OFFSET_W)
frmh = peek(curr_ptr + FRM_OFFSET_H)
sz = wpeek($50000 + OFFSET_DATA_SIZE)
sz = sz - (FRM_OFFSET_DATA + frmw * frmh * 2)
wpoke $50000 + OFFSET_DATA_SIZE, sz
return
'----------------------------
.shift_remaining_frames_along
'----------------------------
gosub get_curr_frame_ptr
curr_ptr = ptr
frmw = peek(curr_ptr + FRM_OFFSET_W)
frmh = peek(curr_ptr + FRM_OFFSET_H)
start_ptr = curr_ptr + FRM_OFFSET_DATA + frmw * frmh * 2
ln = end_ptr - start_ptr + 1
' print "curr_ptr = ";hex$(curr_ptr)
' print "start_ptr = ";hex$(start_ptr)
' print "end_ptr = ";hex$(end_ptr)
' print "ln = ";hex$(ln)
' get key a$
' a$=""
edma OP_COPY, ln, start_ptr, curr_ptr
return
'-----------
.get_end_ptr
'-----------
frame_count = peek($50000 + OFFSET_NUM_FRAMES)
ptr = $50000 + OFFSET_FRAME0
frmidx = 0
if frmidx >= frame_count then begin
cursor 0,0
print clr_line_right$;"invalid block#!"
return
bend
' traverse to find block
for frmidx = 0 to frame_count - 1
frmw = peek(ptr + FRM_OFFSET_W)
frmh = peek(ptr + FRM_OFFSET_H)
ptr = ptr + FRM_OFFSET_DATA + frmw * frmh * 2
next frmidx
return
'------------------
.get_curr_frame_ptr
'------------------
frame_count = peek($50000 + OFFSET_NUM_FRAMES)
' traverse to find block
ptr = $50000 + OFFSET_FRAME0
for frmidx = 0 to frame_count
if frmidx = curr_frame then return
frmw = peek(ptr + FRM_OFFSET_W)
frmh = peek(ptr + FRM_OFFSET_H)
ptr = ptr + FRM_OFFSET_DATA + frmw * frmh * 2
next frmidx
ptr = 0
return
'---------------
.draw_curr_frame
'---------------
frame_count = peek($50000 + OFFSET_NUM_FRAMES)
ptr = $50000 + OFFSET_FRAME0
frmidx = 0
if frmidx >= frame_count then begin
cursor 0,0
print clr_line_right$;"invalid block#!"
return
bend
gosub get_curr_frame_ptr
if ptr = 0 then print "not found!" : return
x = peek(ptr + FRM_OFFSET_X)
y = peek(ptr + FRM_OFFSET_Y)
frmw = peek(ptr + FRM_OFFSET_W)
frmh = peek(ptr + FRM_OFFSET_H)
endx = x + frmw - 1
endy = y + frmh - 1
print "{x13}";clr_line_right$;
print "x=";x;", y=";y;", w=";frmw;", h=";frmh;
print ", ptr=$";hex$(ptr);
print "{x11}";chr$(27);"j";clr_line_right$;"frame=";curr_frame;
print ", nxt=$";hex$(ptr + FRM_OFFSET_DATA + frmw * frmh * 2);
src_char_ptr = ptr + FRM_OFFSET_DATA
src_clr_ptr = ptr + FRM_OFFSET_DATA + frmw * frmh
dest_char_ptr =$40800 + x + y * 80
dest_clr_ptr = $ff80000 + x + y * 80
for yidx = y to endy
edma OP_COPY, frmw, src_char_ptr, dest_char_ptr
edma OP_COPY, frmw, src_clr_ptr, dest_clr_ptr
src_char_ptr = src_char_ptr + frmw
src_clr_ptr = src_clr_ptr + frmw
dest_char_ptr = dest_char_ptr + 80
dest_clr_ptr = dest_clr_ptr + 80
next yidx
return
'-------------------------
.restore_char_under_cursor
'-------------------------
if store_state = STORE_START_POS then begin
poke $40800 + x + y * 80, start_char
poke $ff80000 + x + y * 80, start_color
bend:else begin ' STORE_END_POS
poke $40800 + x + y * 80, end_char
poke $ff80000 + x + y * 80, end_color
bend
return
'-----------
.draw_cursor
'-----------
poke $40800 + x + y * 80, 43
poke $ff80000 + x + y * 80, 1
return
'-----------
.draw_footer
'-----------
cursor 0,49
print clr_line_right$;"frame count=";peek($50000 + OFFSET_NUM_FRAMES);", next-free=$";
print hex$(ptr);
return
'----------------
.store_state_info
'----------------
if store_state = STORE_START_POS then begin
start_char = peek($40800 + x + y * 80)
start_color = peek($ff80000 + x + y * 80)
startx = x
starty = y
bend:else begin ' STORE_END_POS
end_char = peek($40800 + x + y * 80)
end_color = peek($ff80000 + x + y * 80)
endx = x
endy = y
bend
return
'---------
.init_vars
'---------
current_frame = 0
store_state = STORE_START_POS
x = 0
y = 0
curr_frame = 0
return
'---------------------
.locate_next_free_byte
'---------------------
frame_count = peek($50000 + OFFSET_NUM_FRAMES)
frmidx = 0
ptr = $50000 + OFFSET_FRAME0
do while 1
if frmidx = frame_count then begin
bytes_used = ptr-$50000
return
bend
frmw = peek(ptr + FRM_OFFSET_W)
frmh = peek(ptr + FRM_OFFSET_H)
ptr = ptr + FRM_OFFSET_DATA + frmw * frmh * 2
frmidx = frmidx + 1
loop
return
'---------------------
.check_magic_signature
'---------------------
if peek($5fffe) <> 71 or peek($5ffff) <> 73 then begin
wpoke $5fffe, $4947
print "{x93}";clr_line_right$;
print "magic signature applied. reset frame count to zero? (y/n)";
get key a$
if a$ = "y" then begin
wpoke $50000 + OFFSET_DATA_SIZE, 0
poke $50000 + OFFSET_NUM_FRAMES, 0
bend
print "{x93}";clr_line_right$;
bend
return
'---------------
.check_edit_flag
'---------------
if peek($5fffc) = 1 then begin ' editing?
poke $5fffc, 0
curr_frame = peek($5fffd)
gosub get_curr_frame_ptr
startx = peek(ptr + FRM_OFFSET_X)
starty = peek(ptr + FRM_OFFSET_Y)
x = startx + peek(ptr + FRM_OFFSET_W) - 1
y = starty + peek(ptr + FRM_OFFSET_H) - 1
new_frame_flag = 0
gosub save_frame_to_memory_at_ptr
gosub draw_curr_frame
bend
return
'--------------
.yank_selection
'--------------
poke $d020, peek($d020) + 1
' select a region with cursor movement
gosub get_selected_coords_into_x1y1x2y2
' copy it into a basic var
ptr = pointer(clipboard_char&(0))
ln = x2-x1+1
for y = y1 to y2
edma OP_COPY, ln, $40800+x1+y*80, ptr
ptr = ptr + ln
next y
ptr = pointer(clipboard_clr&(0))
for y = y1 to y2
edma OP_COPY, ln, $ff80000+x1+y*80, ptr
ptr = ptr + ln
next y
clipw = x2-x1+1
cliph = y2-y1+1
poke $d020, peek($d020) - 1
return
'-----
.paste
'-----
' copy selection from vars onto screen at current cursor position
x1 = x
y1 = y
x2 = x + clipw - 1
y2 = y + cliph - 1
ptr = pointer(clipboard_char&(0))
ln = x2-x1+1
for y = y1 to y2
edma OP_COPY, ln, ptr, $40800+x1+y*80
ptr = ptr + ln
next y
ptr = pointer(clipboard_clr&(0))
for y = y1 to y2
edma OP_COPY, ln, ptr, $ff80000+x1+y*80
ptr = ptr + ln
next y