forked from blondie7575/WeeGUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
applesoft.s
1222 lines (912 loc) · 24.4 KB
/
applesoft.s
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
;
; applesoft.s
; Applesoft API via the & extension point
;
; Created by Quinn Dunki on 8/15/14.
; Copyright (c) 2014 One Girl, One Laptop Productions. All rights reserved.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Applesoft ROM entry points and constants
;
LINNUML = $0050 ; Scratch pad for calculating line numbers (LSB)
LINNUMH = $0051 ; Scratch pad for calculating line numbers (MSB)
CURLINL = $0075 ; Current line number (LSB)
CURLINH = $0076 ; Current line number (MSB)
CHRGET = $00b1 ; Advances text point and gets character in A
CHRGOT = $00b7 ; Returns character at text pointer in A
TXTPTRL = $00b8 ; Current location in BASIC listing (LSB)
TXTPTRH = $00b9 ; Current location in BASIC listing (MSB)
VARPNT = $0083 ; Return value for PTRGET
FAC = $009d ; Floating point accumulator
AMPVECTOR = $03f5 ; Ampersand entry vector
ERROR = $d412 ; Reports error in X
NEWSTT = $d7d2 ; Advance to next Applesoft statement
GOTO = $d93e ; Entry point of Applesoft GOTO
LINGET = $da0c ; Read a line number (16-bit integer) into LINNUM
FRMNUM = $dd67 ; Evaluate an expression as a number and store in FAC
CHKCOM = $debe ; Validates current character is a ',', then gets it
SYNCHR = $dec0 ; Validates current character is what's in A
AYINT = $e10c ; Convert FAC to 8-bit signed integer
GETBYT = $e6f8 ; Gets an integer at text pointer, stores in X
GETNUM = $e746 ; Gets an 8-bit, stores it X, skips past a comma
PTRGET = $dfe3 ; Finds the Applesoft variable in memory at text pointer
SETHI = $f299 ; Sets value in LINNUM to HIMEM
TOKEN_GOSUB = $b0 ; Applesoft's token for GOSUB
TOKEN_HOME = $97 ; Applesoft's token for HOME
TOKEN_PRINT = $ba ; Applesoft's token for PRINT
TOKEN_MINUS = $c9 ; Applesoft's token for a minus sign
TOKEN_DRAW = $94 ; Applesoft's token for DRAW
TOKEN_PLOT = $8d ; Applesoft's token for PLOT
TOKEN_GET = $be ; Applesoft's token for GET
ERR_UNDEFINEDFUNC = 224
ERR_SYNTAX = 16
ERR_ENDOFDATA = 5
ERR_TOOLONG = 176
MAXCMDLEN = 6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGInitApplesoft
; Sets up Applesoft API
;
WGInitApplesoft:
pha
lda #$4c ; Patch in our jump vector for &
sta AMPVECTOR
lda #<WGAmpersand
sta AMPVECTOR+1
lda #>WGAmpersand
sta AMPVECTOR+2
pla
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGAmpersand
; The entry point from Applesoft. Applesoft text pointer
; will be positioned two after the '&', and accumulator will
; contain first character after the '&'
; Side effects: Clobbers All registers,S0
;
WGAmpersand:
tsx ; Start by caching a valid stack state to return to Applesoft,
stx WG_STACKPTR ; in case we need to do so in a hurry
sta SCRATCH0
ldy #0
ldx SCRATCH0
WGAmpersand_parseLoop:
txa
beq WGAmpersand_matchStart ; Check for end-of-statement (CHRGET handles : and EOL)
cmp #'('
beq WGAmpersand_matchStart
sta WGAmpersandCommandBuffer,y
jsr CHRGET
tax
iny
cpy #MAXCMDLEN+1
bne WGAmpersand_parseLoop
WGAmpersand_parseFail:
ldx #ERR_UNDEFINEDFUNC
jsr ERROR
bra WGAmpersand_done
WGAmpersand_matchStart:
lda #0
sta WGAmpersandCommandBuffer,y ; Null terminate the buffer for matching
ldy #0
ldx #0 ; Command buffer now contains our API call
phx ; We stash the current command number on the stack
WGAmpersand_matchLoop:
lda WGAmpersandCommandBuffer,y
beq WGAmpersand_matchPossible
cmp WGAmpersandCommandTable,x
bne WGAmpersand_matchNext ; Not this one
iny
inx
bra WGAmpersand_matchLoop
WGAmpersand_matchPossible:
lda WGAmpersandCommandTable,x
beq WGAmpersand_matchFound ; Got one!
WGAmpersand_matchNext:
pla ; Advance index to next commmand in table
inc
pha
asl
asl
asl
tax
cpx #WGAmpersandCommandTableEnd-WGAmpersandCommandTable
beq WGAmpersand_matchFail ; Hit the end of the table
ldy #0
bra WGAmpersand_matchLoop
WGAmpersand_matchFound:
pla ; This is now the matching command number
inc
asl
asl
asl
tay
lda WGAmpersandCommandTable-2,y ; Prepare an indirect JSR to our command
sta WGAmpersand_commandJSR+1 ; Self-modifying code!
lda WGAmpersandCommandTable-1,y
sta WGAmpersand_commandJSR+2
; Self-modifying code!
WGAmpersand_commandJSR:
jsr WGAmpersand_done ; Address here overwritten with command
bra WGAmpersand_done
WGAmpersand_matchFail:
pla ; We left command number on the stack while matching
ldx #ERR_UNDEFINEDFUNC
jsr ERROR
WGAmpersand_done:
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGAmpersandBeginArguments
; Begins reading an ampersand argument list
; Side effects: Clobbers all registers
WGAmpersandBeginArguments:
pha
lda #'('
jsr SYNCHR ; Expect opening parenthesis
pla
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGAmpersandNextArgument
; Prepares for the next argument in the list
; Side effects: Clobbers all registers
WGAmpersandNextArgument:
jsr CHRGOT
jsr CHKCOM ; Verify parameter separator
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGAmpersandEndArguments
; Finishes reading an ampersand argument list
; Side effects: Clobbers all registers
WGAmpersandEndArguments:
pha
lda #')'
jsr SYNCHR ; Expect closing parenthesis
pla
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGAmpersandIntArgument
; Reads an integer argument for the current command
; OUT A : The argument
; Side effects: Clobbers all registers
WGAmpersandIntArgument:
jsr CHRGOT
cmp #TOKEN_MINUS
beq WGAmpersandIntArgument_signed
jsr GETBYT
txa
rts
WGAmpersandIntArgument_signed:
jsr CHRGET
jsr GETBYT
txa
eor #$ff
inc
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGAmpersandAddrArgument
; Reads a 16-bit pointer (or integer) argument for the current command
; OUT X : The argument (LSB)
; OUT Y : The argument (MSB)
; Side effects: Clobbers all registers
WGAmpersandAddrArgument:
jsr CHRGOT
jsr LINGET
ldx LINNUML
ldy LINNUMH
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGAmpersandStrArgument
; Reads a string argument for the current command in PARAM0/1.
; This string is copied into privately allocated memory.
; OUT X : Pointer to a stored copy of the string (LSB)
; OUT Y : Pointer to a stored copy of the string (MSB)
; Side effects: Clobbers P0/P1 and all registers
WGAmpersandStrArgument:
lda #'"'
jsr SYNCHR ; Expect opening quote
lda TXTPTRL ; Allocate for, and copy the string at TXTPTR
sta PARAM0
lda TXTPTRH
sta PARAM1
lda #'"' ; Specify quote as our terminator
jsr WGStoreStr
WGAmpersandStrArgument_loop:
jsr CHRGET ; Consume the string for Applesoft
beq WGAmpersandStrArgument_done
cmp #'"' ; Check for closing quote
bne WGAmpersandStrArgument_loop
WGAmpersandStrArgument_done:
lda #'"'
jsr SYNCHR ; Expect closing quote
ldx PARAM0
ldy PARAM1
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGAmpersandTempStrArgument
; Reads a string argument for the current command in PARAM0/1.
; This string is pointed to IN PLACE, and NOT copied.
; OUT X : Pointer to a stored copy of the string (LSB)
; OUT Y : Pointer to a stored copy of the string (MSB)
; OUT A : String length
; Side effects: Clobbers P0/P1 and all registers
WGAmpersandTempStrArgument:
lda #'"'
jsr SYNCHR ; Expect opening quote
lda TXTPTRL ; Grab current TXTPTR
sta PARAM0
lda TXTPTRH
sta PARAM1
WGAmpersandTempStrArgument_loop:
jsr CHRGET ; Consume the string for Applesoft
beq WGAmpersandTempStrArgument_done
cmp #'"' ; Check for closing quote
bne WGAmpersandTempStrArgument_loop
WGAmpersandTempStrArgument_done:
lda #'"'
jsr SYNCHR ; Expect closing quote
; Compute the 8-bit distance TXTPTR moved. Note that we can't simply
; count in the above loop, because CHRGET will skip ahead unpredictable
; amounts
sec
lda TXTPTRL
sbc PARAM0
dec
ldx PARAM0 ; Return results
ldy PARAM1
; pla
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Ampersand API entry points
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGAmpersand_HOME
; Clears the screen
; &HOME
WGAmpersand_HOME:
jsr WGClearScreen
jsr WGBottomCursor
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGAmpersand_DESK
; Render the desktop
; &DESK
WGAmpersand_DESK:
jsr WGDesktop
jsr WGBottomCursor
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGAmpersand_WINDW
; Create a view
; &WINDW(id,style,x,y,width,height,canvas width,canvas height)
WGAmpersand_WINDW:
jsr WGAmpersandBeginArguments
jsr WGAmpersandIntArgument
sta WGAmpersandCommandBuffer+0
jsr WGAmpersandNextArgument
jsr WGAmpersandIntArgument
ora #VIEW_STYLE_APPLESOFT ; Flag this as an Applesoft-created view
sta WGAmpersandCommandBuffer+1
jsr WGAmpersandNextArgument
jsr WGAmpersandIntArgument
sta WGAmpersandCommandBuffer+2
jsr WGAmpersandNextArgument
jsr WGAmpersandIntArgument
sta WGAmpersandCommandBuffer+3
jsr WGAmpersandNextArgument
jsr WGAmpersandIntArgument
sta WGAmpersandCommandBuffer+4
jsr WGAmpersandNextArgument
jsr WGAmpersandIntArgument
sta WGAmpersandCommandBuffer+5
jsr WGAmpersandNextArgument
jsr WGAmpersandIntArgument
sta WGAmpersandCommandBuffer+6
jsr WGAmpersandNextArgument
jsr WGAmpersandIntArgument
sta WGAmpersandCommandBuffer+7
jsr WGAmpersandEndArguments
CALL16 WGCreateView,WGAmpersandCommandBuffer
jsr WGEraseViewContents
jsr WGPaintView
jsr WGBottomCursor
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGAmpersand_CHKBX
; Create a checkbox
; &CHKBX(id,x,y,"title")
WGAmpersand_CHKBX:
jsr WGAmpersandBeginArguments
jsr WGAmpersandIntArgument
sta WGAmpersandCommandBuffer+0
jsr WGAmpersandNextArgument
jsr WGAmpersandIntArgument
sta WGAmpersandCommandBuffer+1
jsr WGAmpersandNextArgument
jsr WGAmpersandIntArgument
sta WGAmpersandCommandBuffer+2
jsr WGAmpersandNextArgument
jsr WGAmpersandStrArgument
stx WGAmpersandCommandBuffer+3
sty WGAmpersandCommandBuffer+4
jsr WGAmpersandEndArguments
CALL16 WGCreateCheckbox,WGAmpersandCommandBuffer
LDY_ACTIVEVIEW ; Flag this as an Applesoft-created view
lda #VIEW_STYLE_APPLESOFT
ora WG_VIEWRECORDS+4,y
sta WG_VIEWRECORDS+4,y
jsr WGPaintView
jsr WGBottomCursor
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGAmpersand_PROG
; Create a progress bar
; &PROG(id,x,y,width)
WGAmpersand_PROG:
jsr WGAmpersandBeginArguments
jsr WGAmpersandIntArgument
sta WGAmpersandCommandBuffer+0
jsr WGAmpersandNextArgument
jsr WGAmpersandIntArgument
sta WGAmpersandCommandBuffer+1
jsr WGAmpersandNextArgument
jsr WGAmpersandIntArgument
sta WGAmpersandCommandBuffer+2
jsr WGAmpersandNextArgument
jsr WGAmpersandIntArgument
sta WGAmpersandCommandBuffer+3
jsr WGAmpersandEndArguments
CALL16 WGCreateProgress,WGAmpersandCommandBuffer
LDY_ACTIVEVIEW ; Flag this as an Applesoft-created view
lda #VIEW_STYLE_APPLESOFT
ora WG_VIEWRECORDS+4,y
sta WG_VIEWRECORDS+4,y
jsr WGPaintView
jsr WGBottomCursor
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGAmpersand_SETV
; Set the 'value' field of the selected view
; &SETV(v)
WGAmpersand_SETV:
jsr WGAmpersandBeginArguments
jsr WGAmpersandIntArgument
pha
jsr WGAmpersandEndArguments
pla
sta PARAM0
jsr WGSetState
jsr WGPaintView
jsr WGBottomCursor
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGAmpersand_BUTTN
; Create a button
; &BUTTN(id,x,y,width,lineNum,"title")
WGAmpersand_BUTTN:
jsr WGAmpersandBeginArguments
jsr WGAmpersandIntArgument
sta WGAmpersandCommandBuffer+0
jsr WGAmpersandNextArgument
jsr WGAmpersandIntArgument
sta WGAmpersandCommandBuffer+1
jsr WGAmpersandNextArgument
jsr WGAmpersandIntArgument
sta WGAmpersandCommandBuffer+2
jsr WGAmpersandNextArgument
jsr WGAmpersandIntArgument
sta WGAmpersandCommandBuffer+3
jsr WGAmpersandNextArgument
jsr WGAmpersandAddrArgument
stx WGAmpersandCommandBuffer+4
sty WGAmpersandCommandBuffer+5
jsr WGAmpersandNextArgument
jsr WGAmpersandStrArgument
stx WGAmpersandCommandBuffer+6
sty WGAmpersandCommandBuffer+7
jsr WGAmpersandEndArguments
CALL16 WGCreateButton,WGAmpersandCommandBuffer
LDY_ACTIVEVIEW ; Flag this as an Applesoft-created view
lda #VIEW_STYLE_APPLESOFT
ora WG_VIEWRECORDS+4,y
sta WG_VIEWRECORDS+4,y
jsr WGPaintView
jsr WGBottomCursor
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGAmpersand_SEL
; Select a view
; &SEL(id)
WGAmpersand_SEL:
jsr WGAmpersandBeginArguments
jsr WGAmpersandIntArgument
jsr WGSelectView
jsr WGAmpersandEndArguments
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGAmpersand_FOC
; Focuses selected view
; &FOC
WGAmpersand_FOC:
jsr WGViewFocus
jsr WGBottomCursor
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGAmpersand_FOCN
; Focuses next view
; &FOCN
WGAmpersand_FOCN:
jsr WGViewFocusNext
jsr WGBottomCursor
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGAmpersand_FOCP
; Focuses previous view
; &FOCP
WGAmpersand_FOCP:
jsr WGViewFocusPrev
jsr WGBottomCursor
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGAmpersand_ACT
; Takes action on focused view
; &ACT
WGAmpersand_ACT:
jsr WGViewFocusAction
jsr WGBottomCursor
lda WG_GOSUB
bne WGAmpersand_ACTGosub
rts
WGAmpersand_ACTGosub:
jmp WGGosub ; No coming back from an Applesoft GOSUB!
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGAmpersand_STACT
; Sets the callback for the selected view
; &STACT(lineNum)
WGAmpersand_STACT:
jsr WGAmpersandBeginArguments
jsr WGAmpersandAddrArgument
stx PARAM0
sty PARAM1
jsr WGAmpersandEndArguments
jsr WGViewSetAction
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGAmpersand_TITLE
; Sets the title for the selected view
; &TITLE("title")
WGAmpersand_TITLE:
jsr WGAmpersandBeginArguments
jsr WGAmpersandStrArgument
stx PARAM0
sty PARAM1
jsr WGAmpersandEndArguments
jsr WGViewSetTitle
jsr WGPaintView
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGAmpersand_CURSR
; Sets the cursor position in selected viewspace
; &CURSR(x,y)
WGAmpersand_CURSR:
jsr WGAmpersandBeginArguments
jsr WGAmpersandIntArgument
sta PARAM0
jsr WGAmpersandNextArgument
jsr WGAmpersandIntArgument
sta PARAM1
jsr WGAmpersandEndArguments
jsr WGSetCursor
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGAmpersand_PRINT
; Prints a string in the selected view at the local cursor
; &PRINT("string")
WGAmpersand_PRINT:
jsr WGAmpersandBeginArguments
jsr CHRGOT ; Experimental alternate parameter support
cmp #'"'
bne WGAmpersand_PRINTint
jsr WGAmpersandTempStrArgument
stx PARAM0
sty PARAM1
pha
jsr WGAmpersandEndArguments
; We're pointing to the string directly in the Applesoft
; source, so we need to NULL-terminate it for printing. In
; order to avoid copying the whole thing, we'll do something
; kinda dirty here.
pla
tay
lda (PARAM0),y ; Cache the byte at the end of the string
pha
lda #0
sta (PARAM0),y ; Null-terminate the string in-place
jsr WGPrint
pla
sta (PARAM0),y ; Put original byte back
rts
WGAmpersand_PRINTint:
; User passed a non-string, so interpret as an ASCII code
jsr WGAmpersandIntArgument
sta WGAmpersand_PRINTintBuffer
jsr WGAmpersandEndArguments
lda #<WGAmpersand_PRINTintBuffer
sta PARAM0
lda #>WGAmpersand_PRINTintBuffer
sta PARAM1
bit WGAmpersand_PRINTrts ; Set overflow
jsr WGPrint
WGAmpersand_PRINTrts:
rts
WGAmpersand_PRINTintBuffer:
.byte 0,0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGAmpersand_SCR
; Sets scroll position of selected view
; &SCR(x,y)
WGAmpersand_SCR:
jsr WGAmpersandBeginArguments
jsr WGAmpersandIntArgument
pha
jsr WGAmpersandNextArgument
jsr WGAmpersandIntArgument
pha
jsr WGAmpersandEndArguments
pla
jsr WGScrollY
pla
jsr WGScrollX
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGAmpersand_SCRBY
; Adjusts scroll position of selected view by a delta
; &SCRBY(x,y)
WGAmpersand_SCRBY:
jsr WGAmpersandBeginArguments
jsr WGAmpersandIntArgument
pha
jsr WGAmpersandNextArgument
jsr WGAmpersandIntArgument
pha
jsr WGAmpersandEndArguments
pla
jsr WGScrollYBy
pla
jsr WGScrollXBy
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGAmpersand_GOSUB
; A custom gosub, because we can. Only for testing at the moment
; &GOSUB
WGAmpersand_GOSUB:
lda #$e8
sta PARAM0
lda #$03
sta PARAM1
jmp WGGosub
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGAmpersand_ERASE
; Erases the contents of the selected view
; &ERASE
WGAmpersand_ERASE:
jsr WGEraseViewContents
jsr WGBottomCursor
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGAmpersand_FILL
; Fills a rectangle with a character
; &FILL(x,y,width,height,char)
WGAmpersand_FILL:
jsr WGAmpersandBeginArguments
jsr WGAmpersandIntArgument
sta PARAM0
jsr WGAmpersandNextArgument
jsr WGAmpersandIntArgument
sta PARAM1
jsr WGAmpersandNextArgument
jsr WGAmpersandIntArgument
sta PARAM2
jsr WGAmpersandNextArgument
jsr WGAmpersandIntArgument
sta PARAM3
jsr WGAmpersandNextArgument
jsr WGAmpersandIntArgument
ora #$80 ; Convert to Apple format
pha
jsr WGAmpersandEndArguments
ply
jsr WGFillRect
jsr WGBottomCursor
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGAmpersand_DRAW
; Strokes a rectangle with a character
; &DRAW(x,y,width,height)
WGAmpersand_DRAW:
jsr WGAmpersandBeginArguments
jsr WGAmpersandIntArgument
sta PARAM0
jsr WGAmpersandNextArgument
jsr WGAmpersandIntArgument
sta PARAM1
jsr WGAmpersandNextArgument
jsr WGAmpersandIntArgument
sta PARAM2
jsr WGAmpersandNextArgument
jsr WGAmpersandIntArgument
sta PARAM3
jsr WGAmpersandEndArguments
jsr WGStrokeRect
jsr WGBottomCursor
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGAmpersand_PNT
; Repaints the selected view
; &PNT
WGAmpersand_PNT:
jsr WGPaintView
jsr WGBottomCursor
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGAmpersand_PNTA
; Repaints all views
; &PNTA
WGAmpersand_PNTA:
jsr WGViewPaintAll
jsr WGBottomCursor
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGAmpersand_PLOT
; Plots a single character (in Apple format)
; &PLOT(x,y,value)
WGAmpersand_PLOT:
jsr WGAmpersandBeginArguments
jsr WGAmpersandIntArgument
sta WG_CURSORX
jsr WGAmpersandNextArgument
jsr WGAmpersandIntArgument
sta WG_CURSORY
jsr WGAmpersandNextArgument
jsr WGAmpersandIntArgument
pha
jsr WGAmpersandEndArguments
pla
jsr WGPlot
jsr WGBottomCursor
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGAmpersand_MOUSE
; Enable or disable the mouse
; &MOUSE(enable)
WGAmpersand_MOUSE:
jsr WGAmpersandBeginArguments
jsr WGAmpersandIntArgument
pha
jsr WGAmpersandEndArguments
pla
beq WGAmpersand_MOUSEoff
jsr WGEnableMouse
rts
WGAmpersand_MOUSEoff:
jsr WGDisableMouse
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGAmpersand_PDACT
; Performs any pending view action
; &PDACT
WGAmpersand_PDACT:
lda WG_MOUSECLICK_X
bmi WGAmpersand_PDACTdone
jsr WGPendingViewAction
jsr WGBottomCursor
WGAmpersand_PDACTdone:
lda WG_GOSUB
bne WGAmpersand_PDACTGosub
rts
WGAmpersand_PDACTGosub:
jmp WGGosub ; No coming back from an Applesoft GOSUB!
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGAmpersand_GET
; A non-blocking version of Applesoft GET. Returns 0 if no key
; is pending
; &GET(A%)
WGAmpersand_GET:
jsr WGAmpersandBeginArguments
jsr PTRGET
lda KBD
bpl WGAmpersand_GETnone ; No key pending
sta KBDSTRB ; Clear strobe and high bit
and #%01111111
pha
bra WGAmpersand_GETstore
WGAmpersand_GETnone:
lda #0
pha
WGAmpersand_GETstore:
ldy #0
lda #0
sta (VARPNT),y
iny
pla
sta (VARPNT),y
; String version:
; sta WG_KEYBUFFER ; Store the key
; lda #1 ; Create an Applesoft string record in the
; sta (VARPNT),y ; variable's location
; iny
; lda #<WG_KEYBUFFER
; sta (VARPNT),y
; iny
; lda #>WG_KEYBUFFER
; sta (VARPNT),y
jsr WGAmpersandEndArguments
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGAmpersand_KILL
; Deletes the selected view
; &KILL
WGAmpersand_KILL:
jsr WGDeleteView