-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtlp.asm
10241 lines (8914 loc) · 431 KB
/
tlp.asm
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
;*******************************************************************************
;* *
;* T H E L E A R N I N G P H O N E *
;* *
;* for the Atari 8-bit Home Computer System *
;* *
;* Reverse engineered and documented assembly language source code *
;* *
;* by *
;* *
;* [LIST GOES HERE] *
;* *
;* *
;* First Release *
;* DD-MMM-YYYY *
;* *
;* Last Update *
;* DD-MMM-YYYY *
;* *
;* THE LEARNING PHONE was created by Vicent Wu / Lane Winner *
;* THE LEARNING PHONE was published by Atari Inc. *
;* *
;*******************************************************************************
; Input file: tlp.bin
.setcpu "6502"
;*******************************************************************************
;* *
;* M E M O R Y M A P *
;* *
;*******************************************************************************
; $0000..$00FF Zero Page - hardware shadow registers and cart variables
; $0100..$01FF Stack
; $0400..$057F Table of addresses to start of each Display List #1 scan line
; $0600..$08FF Programmable character set M2 - zoomed display (64 @ 8x12)
; $0900..$0BFF Programmable character set M3 - zoomed display (64 @ 8x12)
; $0C00..$0D7F Programmable character set M2 - full screen display (64 @ 5x6)
; $0D80..$0EFF Programmable character set M3 - full screen display (64 @ 5x6)
; $1000..$10C9 Display List #1
; $10C9..$130F Display List #2
; $1310..$1355 Additional variables
; $2010..$3DFF 8K frame buffer for Display List #1
; $4000..$9FFF 24K frame buffer for Display List #2
; $A000..$BFFF 8K Cart ROM
;*******************************************************************************
;* *
;* M A C R O D E F I N I T I O N S *
;* *
;*******************************************************************************
.macro RString Arg
.repeat .strlen(Arg), I
.byte .strat(Arg, .strlen(Arg)-1-I)
.endrep
.endmacro
.macro ldi arg1, arg2
lda #arg2
sta arg1
.endmacro
.macro ori arg1, arg2
lda arg1
ora #arg2
sta arg1
.endmacro
.macro add16i8 arg1, arg2
clc
lda arg1
adc #arg2
sta arg1
bcc :+
inc arg1+1
:
.endmacro
.macro inc16 arg1
inc arg1
bcc :+
inc arg1+1
:
.endmacro
.segment "SEG1"
;*******************************************************************************
;* *
;* S Y S T E M S Y M B O L S *
;* *
;*******************************************************************************
TSTDAT := $0007
WARMST := $0008 ; Warmstart flag. 0->Cold-started $FF->Warm-started
POKMSK := $0010 ; POKEY interrupt mask.
RTCLOK := $0012 ; RTCLOK+0: increments every 65536 VBLANKS (NTSC 18.2 minutes)
; RTCLOK+1: increments every 256 VBLANKS (NTSC 4.27 seconds)
; RTCLOK+2: increments every VBLANK (NTSC 1/60 second)
ICAX1Z := $002A
ATRACT := $004D ; Attract mode timer and flag
VPRCED := $0202 ; Vector to serial peripheral proceed line vector
VINTER := $0204 ; Vector to serial peripheral interrupt vector
VSERIN := $020A ; Vector to serial receive-data-ready interrupt
VTIMR1 := $0210 ; Vector to POKEY timer 1 interrupt
CDTMA1 := $0226 ; System timer one jump address
SRTIMR := $022B
SDMCTL := $022F ; Direct memory access control
DLIST := $0230 ; Starting address of the display list.
SSKCTL := $0232 ; Serial port control register
GPRIOR := $026F ; Priority selection register for screen objects
STICK0 := $0278 ; Joystick 0
STRIG0 := $0284
SHFLOK := $02BE ; Flag for shift and control keys
PCOLR0 := $02C0 ; Color for player 0 and missile 0
COLOR1 := $02C5 ; Playfield 1 color register
COLOR2 := $02C6 ; Playfield 2 color register
COLOR3 := $02C7 ; Playfield 3 color register
COLOR4 := $02C8 ; Playfield 4 color register
HELPFG := $02DC ; Help key status
DVSTAT := $02EA ; Device status register.
CH := $02FC ; Keyboard character code.
; Device Control Block
DDEVIC := $0300 ; Device bus ID (RS232 is $50).
DUNIT := $0301 ; Device unit number.
DCOMND := $0302 ; Device command.
DSTATS := $0303
DBUF := $0304
DTIMLO := $0306 ; Time-out value for a handler in seconds
DBYT := $0308 ; Number of bytes transferred to/from data buffer
DBYTLO := DBYT ; Number of bytes transferred to/from data buffer
DBYTHI := $0308 ; Number of bytes transferred to/from data buffer
DAUX1 := $030A ; Device Command Arg 1
DAUX2 := $030B ; Device Command Arg 1
HATABS := $031A ; Handler Address Table
; I/O Control Block
ICCOM := $0342
ICBA := $0344 ; Address to buffer for read/write operations
ICBL := $0348 ; IO buffer length
ICAX1 := $034A
ICAX2 := $034B
; GTIA (D000-D01F)
HPOSM0 := $D004 ; Position of touch screen cross-shaped cursor (right half)
HPOSM1 := $D005 ; Position of touch screen cross-shaped cursor (left half)
HPOSM2 := $D006 ; Position of "=" part of "F" in joystick function key mode
HPOSM3 := $D007 ; Position of "|" part of "F" in joystick function key mode
SIZEM := $D00C ; Size for all missiles
GRACTL := $D01D ; Turn on/off player missiles or latch triggers
CONSOL := $D01F ;
; POKEY (D200-D21F)
AUDCTL := $D208 ; Audio control.
AUDF1 := $D200 ; Audio channel 1 frequency.
AUDF2 := $D202 ; Audio channel 2 frequency.
AUDF3 := $D204 ; Audio channel 3 frequency.
AUDF4 := $D206 ; Audio channel 4 frequency.
AUDC1 := $D201 ; Audio channel 1 control.
AUDC2 := $D203 ; Audio channel 2 control.
AUDC3 := $D205 ; Audio channel 3 control.
AUDC4 := $D207 ; Audio channel 4 control.
STIMER := $D209 ; Start timer.
SKREST := $D20A ; Reset serial port status.
RANDOM := SKREST ; Random number generator.
SEROUT := $D20D ; Serial port input.
SERIN := SEROUT ; Serial port output.
IRQEN := $D20E ; Interrupt request (IRQ) enable.
IRQST := IRQEN ; IRQ status.
SKCTL := $D20F ; Serial port control.
SKSTAT := $D20F ; Serial port status.
; PIA (D300-D31F)
PIA := $D300 ; Port A.
PORTA := PIA ; Port A.
PACTL := $D302 ; Port A control.
PBCTL := $D303 ; Port B control.
; ANTIC (D400-D41F)
DMACTL := $D400 ; Direct Memory Access (DMA) control
PMBASE := $D407 ; MSB of the player/missile base address
WSYNC := $D40A ; Wait for horizontal sync.
; OS ROM (D800-FFFF)
CIOV := $E456
SIOV := $E459 ; Serial Input/Output utility entry point
SETVBV := $E45C
XITVBV := $E462
;*******************************************************************************
;* *
;* C A R T S Y M B O L S *
;* *
;*******************************************************************************
; MPP Microbit 300 Driver Symbols
BAUD := $45 ; Divide by n frequency for 300 baud. Noted in MPP Smart Term 4.1 Source Page 32
INPBIT := $00FD ; Input bit
OUTBIT := $00FE ; Output bit
INPBUF := $0F00
INPBFPT := $133E ; Used for offset to INPBUF
BUFLEN := $133F
OUTBFPT := $1340
CHARACTER := $1347 ; placeholder for now TODO
INP := $1348
OUTBUF := $1349
OUTINT := $134A
INPINT := $134B
ISTOP := $134C
; Other
L0080 := $0080 ; Address to store self-modifying code during init
INIT_DL := $0080 ; Address to store self-modifying code during init
CURSOR2_X := $009C ; X coord for cursor (zoomed display) (0->left boundary, 511->right)
CURSOR2_Y := $009E ; Y coord for cursor (zoomed display) (0->bottom of screen, 383->top)
byte_9F := $009F
CURSOR2_X_OLD := $00A0
CURSOR2_Y_OLD := $00A2
CURSOR1_X := $00A4 ; X coord for cursor (full screen display) (0->left boundary, 311->right, multiples of 5)
CURSOR1_Y := $00A6 ; Y coord for cursor (full screen display) (0->bottom of screen, 191->top, multiples of 6)
REND := $00A7 ; Right mask for BLOCK
BLOCK1_X1 := $00A8
BLOCK1_Y1 := $00AA
CURSOR1_X_OLD := $00A8
CURSOR1_Y_OLD := $00AA
LEND := $00AB ; Left mask for BLOCK
MARGIN2 := $00AC ; 2-byte Left margin (zoomed display)
MARGIN1 := $00AE ; 2-byte Left margin (full screen)
PLOT_MODE := $00B0 ; char mode $00->mode rewrite,$40->inverse video screen mode,$80->mode write,$C0->mode erase
CURRENT_BAUD := $00B1 ; Current 850 baud rate: $FF->300 $00->1200
byte_B2 := $00B2 ; Used during init
IS_MPP := $00B2 ; If Microbits 300 then 1 else 0
DATA_MODE := $00B3 ; 4->point,5->line,1->block,7->text,0->load mem
ESC_CODE := $00B4 ; $00->ESC {R,S,T,V} $01->ESC 2 (Load Coordinate) $02->ESC Q (SSF) $03->ESC Y (Load Echo commnd) $04->ESC W (Load Memory Address command) $05->ESC U (select mode 6)
DATA_FRAME_SZ := $00B5 ; Number of bytes expected in data frame (1->byte, 3->word, ?->coordinate TODO)
GRAPHIC_FLG := $00B5 ; $80->graphic (point, line, or block) $01->text
SERIN_BUF_IDX := $00B6 ; Index or count of characters received from PLATO
CURRENT_CHSET := $00B7 ; $00->M2 $01->M3 $02->M0 $03->M1
CURRENT_DL := $00B8 ; Current Display List (80 or FF = DL #1, 00 = DL #2)
SEND_FLG := $00B9 ; $00->Nothing to send
IS_16K := $00BA ; TODO Flag for system < 48K RAM? (no support for zoomed display)
CORDX := $00BB ; 2-byte explicit X coordinate from PLATO
CORDY := $00BD ; 2-byte explicit Y coordinate from PLATO
byte_BC := $00BC
byte_BD := $00BD
byte_BE := $00BE
TOUCH_X := $00BF ; Current X position of simulated touch screen - resolution is 16 positions ($00-$0F)
TOUCH_Y := $00C0 ; Current Y position of simulated touch screen - resolition is 16 positions ($00-$0F)
UI_MODE := $00C1 ; Current user interface mode ($00->full-screen, $FF->zoomed, $01->touch screen, $FE->zoomed from touch screen, $02->joystick func keys)
JSTICK_DIR := $00C2 ; Direction of joystick (normal 14->up, 7->right, etc, but center = 0)
CROSS_Y := $00C3 ; Touch screen cross-shaped cursor vertical position
CROSS_X := $00C4 ; Touch screen cross-shaped cursor horizontal position
JSTICK_FN_DLY := $00C5 ; Counter that restricts handle events to no
JSTICK_TR_DLY := $00C6 ; Counter that restricts trigger events to no more than 2 times per second.
JSTICK_TR := $00C7 ; State of joystick trigger ($00=pressed, $FF->clear)
JSTICK_FN := $00C8 ; Direction of joystick-mapped function keys: 0D->U(NEXT),02->D(BACK),0C->L(LAB),$12->R(DATA)
COMPR := $00C9 ; Compressed graphics mode flag (full screen display)
CURRENT_SIZE := $00CA ; Character Size $00->size 0 (normal) $FF->size 2 (bold/doubled) [temporarily $7F->size 2 in full-screen]
byte_CB := $00CB ; IRQ enable flag: 0->Enable Serial Out IRQs
SEROUT_IRQ_FLG := $00CB ; VSEROR VSEROC IRQ enable flag: 0->Enable Serial Out IRQs
SERIN_FLG := $00CC ; SERIN_FLG
byte_CD := $00CD
MOD6_BUF := $00CE ; Mode 6 buffer
FG_COLOR_DL2 := $00D0 ; Text luminance used in Display List #2 (zoomed)
BG_COLOR_DL2 := $00D1 ; Background / border hue/luminance used in Display List #2
FG_COLOR_DL1 := $00D2 ; Text luminance used in Display List #1 (small text)
BG_COLOR_DL1 := $00D3 ; Background / border hue/luminance used in Display List #1
XDLO := $00D4 ; TODO Delta X when calculating slope?
XDHI := $00D5
YDLO := $00D6 ; TODO Delta Y when calculating slope?
YDHI := $00D7
CURR_WORD := $00D8 ; Index of current 16 bit word while scaling fonts in load_memory
VAR := $00D8 ; working variable
PIX_CNT := $00D9 ; Number of pixels set in 8x16 programmable character bitmap
TMP := $00D9 ; working variable
MODE_CHANGE := $00DA ; Flag set when change to current terminal mode (text, point, line, block, etc) $00->mode changed non-zero->continuation of current mode
PLATO_WORD := $00DB ; 16-bit PLATO word (See s0ascers 3.1.2.4.2)
off_DD := $00DD ; Temp variable
JSTICK_X := $00DD ; VBI: Current joystick direction X-axis (-1=left +1=right)
JSTICK_Y := $00DE ; VBI: Current joystick direction Y-axis (-1=up +1=down)
DL2_TEMP := $00DF ; Pointer used while deriving display list #2
DL2_WIND := $00E1 ; Pointer into 24K frame buffer for origin (0,0) of zoomed display
BIT_8x16 := $00E3 ; Pointer to 8x16 character bitmap during load_memory
YOUT := $00E3 ; Pointer to a byte in screen RAM. Used to plot new data to screen.
CNUM := $00E5 ; 16-bit address to bitmap of character to be drawn on screen
PLATO_CHAR := $00E7 ; PLATO/ASCII character code to be sent to PLATO
CHSET_BASE := $00E8 ; current character set base (full-screen display)
CHSET_BASE2 := $00EA ; current character set base (zoomed)
OBFCODE_PTR := $00EC
STR_PTR := $00EC ; String pointer during print_string
SRC_ROW := $00EC ; index used during load_memory (source row)
X1LO := $00EC ; Line endpoint X1
X1HI := $00ED
STR_LEN := $00EE ; String length during print_string
TAR_ROW := $00EE ; index used during load_memory (target row)
Y1LO := $00EE ; Line endpoint Y1
Y1HI := $00EF
X0LO := $00F0 ; Line endpoint X0
X0HI := $00F1 ;
Y0LO := $00F2 ; Line endpoint Y0
Y0HI := $00F3 ;
BLOCK_X1 := $00F0 ; block erase cursor position (TCRSX in Atari code)
BLOCK_Y1 := $00F2 ; block erase cursor position (TCRSY in Atari code)
BIT_5x6 := $00F4 ; Pointer to 5x6 character bitmap during load_memory
SUMLO := $00F4 ; vector draw work variables
SUMHI := $00F5 ;
INDLO := $00F6
INDHI := $00F7
INVX := $00F8 ; X0<X1 or X1<X0
INVY := $00F9 ; Y0<Y1 or Y1<Y0
off_FA := $00FA
BLOCK_X2 := $00F8 ; block erase cursor position (CURSX in Atari code)
BLOCK_Y2 := $00FA ; block erase cursor position (CURSY in Atari code)
DELLO := $00FA ;
DELHI := $00FB
YM := $00FC ; Which axis (X or Y) is the major axis between 2 coords (1->Y-axis, 0->X-axis)
byte_FF := $00FF ; Modem buffer length
MOD6_ACTION := $00FF ; Mode 6 Action code ($FF->Initial state, receive next action)
BUF32 := $1310 ; 32 byte buffer circular buffer
byte_1330 := $1330
byte_1336 := $1336
byte_133a := $133A
byte_133c := $133C ; Status byte? TODO
byte_133d := $133D ; Status byte? TODO
byte_133e := $133E
byte_133f := $133F
byte_1340 := $1340
byte_1341 := $1341
BUF32_IDX := $1342 ; Offset into circular 32 byte buffer
byte_1343 := $1343
byte_1344 := $1344
TIMER_EVENT := $1345 ; System Timer Flag: 0->timer expired (triggered IRQ)
byte_1346 := $1346 ; Handler Device Type (R:)???
byte_1347 := $1347
byte_1348 := $1348
byte_134c := $134C
;off_134d := $134D
;byte_134f := $134F
;byte_1350 := $1350
;word_1351 := $1351
MOD6A := $134D ; Mode 6 - Pointer to Mode 6 subroutine. Address received from PLATO host.
MOD6_D1 := $134F ; Mode 6 - Flag
MOD6_1ST := $1350 ; Mode 6 - Flag for 1st pass ($FF = 1st pass)
MOD6_N := $1351 ; Mode 6 - Number of bytes expected for download into MOD6_BUF
CURRENT_ECHO := $1353 ; $00->local echo $80->remote echo
DATA_FRAME_SZ2 := $1354 ; Previous data frame size - used to restore previous state
CURRENT_SELECT := $1355 ; Which color aspect is modified with SELECT ($00->c, $80->b, $C0->t)
L2000 := $2000
PIX_WEIGHTS := $3E10 ; Table of pixel weights used to scale 8x16 bitmap to 5x6
L3E2E := $3E2E
SERIN_BUF := $3E2E ; Buffer for characters received from PLATO
L3E33 := $3E33
test_if_rom := $3E33
SCREEN_DL1 := $2010 ; Start of 8k framebuffer for video
SCREEN_DL2 := $4000 ; Start of 24k framebuffer for video
L6000 := $6000
L8000 := $8000
ch_mem_m2_DL2 = $0600 ; Base address for programmable font M2 (64 chars @ 12 bytes/char)
ch_mem_m3_DL2 = $0900 ; Base address for programmable font M3 (64 chars @ 12 bytes/char)
ch_mem_m2_DL1 = $0C00 ; Base address for programmable font M2 (64 chars @ 6 bytes/char)
ch_mem_m3_DL1 = $0D80 ; Base address for programmable font M3 (64 chars @ 6 bytes/char)
; Keyboard scan codes
key_0 = $32
key_1 = $1F
key_3 = $1A
key_a = $3F
key_b = $15
key_c = $12
key_d = $3A
key_e = $2A
key_f = $38
key_h = $39
key_l = $00
key_m = $25
key_n = $23
key_p = $0A
key_s = $3E
key_t = $2D
key_z = $17
key_apos = $73 ; apostrophe / single-quote
key_at = $75 ; '@'
key_hash = $5A ; '#'
key_amper = $5B ; '&'
key_tab = $2C
key_backs = $34 ; backspace
key_return = $0C
key_space = $21
key_equal = $0F ; '='
key_pipe = $4F ; '='
key_gt = $37 ; '>'
key_lt = $36 ; '<'
key_plus = $06 ; '+'
key_bkslash = $46
key_minus = $0E ; '-'
key_mult = $07 ; '*'
key_caret = $47
key_div = $26 ; '/'
key_caps = $3C ; 'CAPS/LOWR'
key_atari = $27 ; '/|\'
mod_shift = $40 ; modifier when SHIFT key is held
mod_ctrl = $80 ; modifier when CTRL key is held
.org $A000
;*******************************************************************************
;* *
;* cart_start *
;* *
;* Second entry point after system restart *
;* *
;*******************************************************************************
; DESCRIPTION
; After a cold or warm start, the OS runs the cart_init routine found towards
; the end of the cart's address space, then jumps to here.
cart_start: ; A000
jsr sub_register_R ; Add R device to HATABS
jsr init_graphics ; Initialize display lists, colors
jsr display_title ; Display program title and copyright
ldy #open_k-tab_iocb ;
jsr call_cio_or_err ; Open K: on channel #2
;**(n) Attempt to open an Atari direct connect modem using T: handler **********
ldy #open_t-tab_iocb ;
jsr call_cio ; Try to open T: on channel #1
bmi :++ ; If cio returned error then skip ahead
;**(n) Atari direct-connect modem detected *************************************
lda #$1A ; Move cursor
sta CURSOR2_X
ldy #$33 ; String length - 1
lda #<LB8DF ; "After the phone has a high..."
ldx #>LB8DF ;
jsr print_string ;
: lda CH ; Wait for key press
cmp #$FF ;
beq :- ;
ldx #$FF ; Some key press occurred
stx CH ; Clear keyboard register
;** (n) If user presses '1' instead of RETURN try to set baud to 1200 **********
cmp #key_1 ; if last key press <> '1'
bne :+++ ; then skip ahead
jsr display_title ; otherwise clear screen and..
;** (n) Try changing baud rate and re-opening channel #1 ***********************
: jsr close_ch1 ; Close CIO channel #1
jsr open_modem ; Attempt to open R: on channel #1 at CURRENT_BAUD
bmi :+ ; if unsuccessful then default to Microbits 300
lda #<LB91C ; otherwise print "1200 baud"
ldx #>LB91C ;
ldy #$08 ; String length - 1
jsr print_string ;
jmp kernel ; and proceed to main loop
;** (n) If all else fails assume Microbits 300 ********************************
: jsr config_mpp ;
jmp kernel ; Skip test and goto main loop
;** (n) Test 850 or direct-connect modem **************************************
: lda #$4C ; x100 1100
jsr test_baud ; Send test??
: lda #$46 ; x100 0110
jsr test_baud ; Send test??
lda DVSTAT+1 ; Keep trying until successful...
bpl :- ; ...then fall through to main loop.
;*******************************************************************************
;* *
;* kernel *
;* *
;* main program loop *
;* *
;*******************************************************************************
kernel: ; A05E
jsr proc_keyboard ; Process/send keyboard events
jsr proc_joystick ; Process/send joystick events
jsr send_mod6_data ; Send data to PLATO if any
lda SERIN_FLG ; Any data received?
beq kernel ; No? -->
jsr proc_serial_in ; Process incoming data
bcc kernel ; Any more work? No? -->
jsr draw ; Process graphic data
lda #$00 ;
sta SERIN_BUF_IDX ; Clear counter/index
beq kernel ; -->
;*******************************************************************************
;* *
;* proc_serial_in *
;* *
;* Read data from serial. Could be instruction or data. *
;* *
;*******************************************************************************
; DESCRIPTION
;
; This subroutine reads byte from the serial port. The byte could be:
; a) the second character in an escape sequence (previous character was ESC).
; b) a control code (ASCII code in non-printable range (< #$20)
; c) an alpha code (data mode is alpha/text and ASCII code in printable range)
; d) a graphics code (data mode is graphic)
;
; Returns to kernel with carry flag set or unset.
; If carry is clear then there's nothing left to do in kernel and the main loop
; can begin from the top.
proc_serial_in: ; A079
ldy #read_ch1-tab_iocb ; Prepare CIO for get char
jsr call_cio_or_err ; A = char read from CIO
and #$7F ; Remove/ignore parity bit
;** Process escape sequence ****************************************************
bit DATA_MODE ; Bit 7 set if prev char was ESC
bmi proc_esc_seq ;
;** Process control code *******************************************************
cmp #$20 ; is it a control code?
bcs :++ ; no? skip.
jsr proc_control_ch ; yes? process control code.
: clc ; All done. Tell kernel
rts ; ...to go to next iteration.
;** Process character depending on current data mode ***************************
: ldx SERIN_BUF_IDX ; Get PLATO input buffer index
sta SERIN_BUF,x ; Store char (A) to buffer
inx ;
stx SERIN_BUF_IDX ; Increment index
ldy GRAPHIC_FLG ; Is mode currently $01->alpha?
bpl :+ ; Yes? skip ahead.
;** Here if data mode is $80->graphic. *****************************************
;** If data >= #$60 return to kernel with more work to do. *********************
cmp #$60 ; 0110 0000
bcs :-- ; Return with carry set.
cmp #$40 ;
rts ; A09F 60 `
;** Here if data mode is $01->alpha. Return to kernel with more work to do *****
: cpx GRAPHIC_FLG ;
rts ; Return with carry set.
;*******************************************************************************
;* *
;* draw *
;* *
;* Depending on current data mode, draw point, line, block, or text *
;* *
;*******************************************************************************
; DESCRIPTION
; This subroutine will jump to a Load or Mode command.
; Upon arrival, the overflow status bit is set if currently processing an Escape
; sequence.
draw: ; A0A3
ldy #$00 ;
sty SERIN_BUF_IDX ; Clear
bvc :+++ ; Mode command? Skip ahead-->
;-------------------------------------------------------------------------------
; Here if prev char was ESC
;-------------------------------------------------------------------------------
ldy ESC_CODE ;
cpy #$05 ; Mode 6?
beq :+ ; yes? skip to unpack_word.
jsr restore_mode ; Restore previous data frame size
tya ; Test ESC_CODE
bne :+ ; Not 0->set_mode_7? -->
rts ; Yes 0->set_mode_7 (nothing to do?)
: dey ; Decrement ESC_CODE to accomodate jump table index
beq :+ ; Was it 1->get_plato_coords? (not words) , skip unpack_word-->
jsr unpack_word ; Unpack 3 byte data frame
;-------------------------------------------------------------------------------
; Jump to Load Subroutine using push/rts trick
;-------------------------------------------------------------------------------
: lda tab_esc_subs_HI,Y ; MSB of subroutine address
pha ;
lda tab_esc_subs_LO,Y ; LSB of subroutine address
pha ;
rts ; Trick RTS to 'return' to subroutine.
;-------------------------------------------------------------------------------
; Jump to Data Mode Subroutine using push/rts trick
;-------------------------------------------------------------------------------
: ldx DATA_MODE ; Get jump table offset (7 = plot_alpha)
lda tab_mode_subs_HI,X ; MSB of subroutine address
beq :+ ; RTS to kernel if subroutine is undefined
pha ;
lda tab_mode_subs_LO,X ; LSB of subroutine address
pha ; Otherwise trick RTS to 'return' to
: rts ; subroutine
;*******************************************************************************
;* *
;* proc_esc_seq *
;* *
;* Remove ESC flag and that signaled previous char was ESC. *
;* *
;*******************************************************************************
proc_esc_seq: ; A0D2
asl DATA_MODE ; Strip bit 7 flag that told us
lsr DATA_MODE ; ... prev char was ESC.
jsr proc_esc_seq2 ;
clc ; Clear carry to tell kernel
: rts ; ...all pending work is done.
;*******************************************************************************
;* *
;* proc_esc_seq2 *
;* *
;* Examine which escape character was received and do what it says *
;* *
;*******************************************************************************
; DESCRIPTION
; This subroutine examines the
proc_esc_seq2: ; A0DB
;** If ESC sequence is > ESC Z then it's undefined, return *********************
cmp #$5B ; is escape sequence > "Z"?
bcs :- ; yes? undefined. RTS
cmp #$3D ; is sequence ESC '=' (color)?
beq get_colorf ; yes? Jump.
;** If ESC sequence is >= ESC ! then use character code as-is as index *********
cmp #$20 ; is ESC seq >= "!"?
bcs :+ ; yes? Skip "adc #$20"
;** If ESC sequence is < ESC ! then add 32 *************************************
adc #$20 ; Change offset into jump
bcc proc_control_ch ; ...table and process
;** If ESC 2 doesn't have a lookup table entry, check for it here **************
: cmp #'2' ; if ESC 2 (or GS?) then process
beq load_coord ; ..."Load Coordinate".
;** If ESC sequence < ESC @ then it's undefined, return ************************
cmp #'@' ; Anything else less than
bcc :-- ; ...ESC @ is undefined. RTS
;*******************************************************************************
;* *
;* proc_control_ch *
;* *
;* Jumps to a subroutine for a received control code. *
;* *
;*******************************************************************************
; DESCRIPTION
; Control codes are those less than $20 (space). This subroutine derives
; an address to a subroutine that will handle the details of the control code.
; Any unexpected control codes should result in an RTS.
;
; (excerpt from s0ascers 3.2.3.1)
;-------------------------------------------------------------------------------
; Control codes and escape sequences are used to control the terminal's
; mode (text, point, line, etc.) and to issue commands (such as erase screen,
; set writing mode, and so forth).
;-------------------------------------------------------------------------------
; (excerpt from s0ascers 6.1)
;-------------------------------------------------------------------------------
; CONTROL HEX
; CHARACTER CODE
; BS 08 Backspace. Moves one character width back.
; HT 09 Tab. Moves one character width.
; LF 0A Linefeed. Moves one character height down.
; VT 0B Vertical tab. Moves one character height up.
; FF 0C Form feed. Set (X,Y) position to top of page.
; CR 0D Carriage return. Set (X,Y) to margin on next line.
; EM 19 Selects block write/erase mode (mode 4).
; ESC 1B Causes terminal to examine the next character to
; determine if it is a valid escape sequence.
; FS 1C Selects point-plot mode (mode 0).
; GS 1D Selects draw line mode (mode 1).
; US 1F Selects alpha mode (mode 3).
;
; Note: control codes received not included here should be ignored.
;-------------------------------------------------------------------------------
proc_control_ch: ; A0F3
tax ; Save control code into X
;** Lookup address for control char's subroutine from table ********************
clc ;
lda #<(esc_seq_ff-1) ; Lookup LSB for subroutine using
adc JUMTAB,X ; ...control code as offset into table.
tay ; Stash into Y
lda #$00 ;
sta SERIN_BUF_IDX ;
adc #>(esc_seq_ff-1) ; Set MSB for subroutine (all are page A3)
;** Trick RTS to jump to the derived address using address found on stack ******
pha ; Push subroutine's MSB
tya ;
pha ; Push subroutine's LSB
rts ; Jump to control code routine
;*******************************************************************************
;* *
;* get_colorf *
;* *
;* Received ESC = from PLATO host (color)
;* *
;*******************************************************************************
; DESCRIPTION
; Get foreground and background color bytes and do nothing (unsupported)
get_colorf: ; A185
ldx #$02 ; Read 2 bytes
lda #$00 ; and do nothing
beq save_mode ; -->
;*******************************************************************************
;* *
;* load_coord *
;* *
;* Received ESC 2 from PLATO host *
;* *
;*******************************************************************************
; DESCRIPTION
load_coord: ; A10B
ror DATA_FRAME_SZ ; Let $B5 = $B5 / 2
lda #$01 ; Let A = 1
bne :+ ; --> Save A to B4
;*******************************************************************************
;* *
;* save_mode *
;* *
;* Called when switching between data mode and esc code routines? (TODO) *
;* *
;*******************************************************************************
; DESCRIPTION
; This subroutine stashes the current data frame size and sets a flag in
; DATA MODE.
;
; Parameters:
; X = Number of bytes to read
; A = index into jump table
; A X
; -- --
; 0 3 Set mode 7
; 1 ? Load Coord
; 2 3 Select Special Function
; 3 3 Load Echo
; 4 3 Load Memory Address
; 5 3 Set mode 6
save_mode:
ldy DATA_FRAME_SZ ; Save current data mode frame size
sty DATA_FRAME_SZ2 ;
stx DATA_FRAME_SZ ; Save new data mode frame size
: sta ESC_CODE ; Save new data mode jump table index
lda DATA_MODE ; Set bit 6 in DATA_MODE index/flag
ora #%01000000 ;
bne :+ ; -->
;*******************************************************************************
;* *
;* restore_mode *
;* *
;* Restores previous data frame size, sets flag *
;* *
;*******************************************************************************
; DESCRIPTION
; This subroutine restores the prevous data frame size and clears a flag in
; DATA MODE.
restore_mode: ; A120
lda DATA_FRAME_SZ2 ; Restore previous data frame size
sta DATA_FRAME_SZ ;
lda DATA_MODE ; Clear bit 6 in DATA_MODE index/flag
and #%10111111 ;
: sta DATA_MODE ;
: rts ;
;*******************************************************************************
;* *
;* send_mod6_data *
;* *
;* Launch point for sending Mode 6 data to the PLATO host *
;* *
;*******************************************************************************
; DESCRIPTION
; These's no evidence this is ever called.
send_mod6_data: ; A12C
lda SEND_FLG ; Anything to send?
beq :- ; No? Return to kernel
jmp (MOD6A) ; Address received from PLATO host
;*******************************************************************************
;* *
;* proc_mode_6 *
;* *
;* User Program Mode *
;* *
;*******************************************************************************
; DESCRIPTION
; This subroutine is curious in that it is likely never executed. Mode 6 is
; used for Micro PLATO to download and execute instructions from the PLATO host.
; Such functionality for the 6502 is undocumented in s0ascers.
;
; Action Description
; ----- -----------
; $FF Initial state - Receive next action
; $00 Send char at (MOD6_BUF),0 to PLATO
; $01 Received data address (MOD6_BUF) from PLATO
; $02 Received data from PLATO, save it to (MOD6_BUF),Y (up to 2 bytes per pass)
; $03 Received subroutine address (MOD6A) from PLATO, Save it.
; $04 Received subroutine address (MOD6A) from PLATO, Run it.
;
;-------------------------------------------------------------------------------
; excerpt from 3.2.3.1.2.6
;-------------------------------------------------------------------------------
; The user program mode is used to communicate with "user programs." The main
; such user program is the Micro PLATO interpreter. When the resident receives
; data from the host in this mode it should call the routine whose address is
; stored in the memory location for this user mode. The addresses for these
; routines are kept in the Micro PLATO variables MOD5A, MOD6A and MOD7A. If the
; interface to Micro PLATO is not implemented, data in this mode should be
; ignored.
;
; Mode five is selected by ESC T (1B 54 hex), mode six by ESC U (1B 55 hex) and
; mode 7 by ESC V (1B 56 hex). The host sends data in word format in this mode
; (see section 3.1.2.4.2 for a description of word format). The entire eighteen
; bits of the word are passed to the user program.
;
; If the address stored in MODx is zero, then this data should be ignored and
; the resident should simply return.
;
; If the user program address is non-zero, it is a pointer to the routine to be
; called. The data is passed to the user program in the C, D and E registers on
; the Z80. Bits 1 through 8 are passed in E, 9 through 16 in D and 17 through
; 18 in the lowest two bits of C. See appendix C for the equivalent registers
; on other microprocessors.
;-------------------------------------------------------------------------------
proc_mode_6: ; A133
ldy PLATO_WORD+1 ;
lda PLATO_WORD ;
ldx MOD6_ACTION ; $FF->Initial State
bpl :+++ ; Returning State? -->
;-------------------------------------------------------------------------------
; Initial pass for current transaction
;-------------------------------------------------------------------------------
iny ; Test PLATO_WORD+1
bne :+ ; PLATO_WORD+1 <> $FF? --> RTS
tax ; Test PLATO_WORD
bmi :++ ; PLATO_WORD >= $80? -->
sta MOD6_ACTION ; PLATO_WORD contains next action
: rts ; Quit
;-------------------------------------------------------------------------------
; Here if PLATO_WORD >= $80 and PLATO_WORD == $FF
;-------------------------------------------------------------------------------
: inx ; X is now 0
stx MOD6_D1 ; MOD6_D1 = 0
jmp mod6_terminate ; Send ESC F h and RTS
;-------------------------------------------------------------------------------
; Here if MOD6_ACTION between $00 and $7F
;-------------------------------------------------------------------------------
: bit MOD6_D1 ;
bpl :+ ;
rts ;
;-------------------------------------------------------------------------------
; Switch on MOD6_ACTION
;-------------------------------------------------------------------------------
: ldx MOD6_ACTION ;
beq mod6_s0 ; MOD6_ACTION = 0? -->
dex ;
beq mod6_s1 ; MOD6_ACTION = 1? -->
dex ;
beq mod6_s2 ; MOD6_ACTION = 2? -->
dex ;
beq mod6_s3 ; MOD6_ACTION = 3? -->
dex ;
beq mod6_s4 ; MOD6_ACTION = 4? -->
rts ; Else Quit
;-------------------------------------------------------------------------------
; MOD6_ACTION = 0 : Send data byte at (MOD6_BUF),0 to PLATO
;-------------------------------------------------------------------------------
mod6_s0:
sty MOD6_BUF+1 ; MOD6_BUF = PLATO_WORD
sta MOD6_BUF ;
ldy #$00 ;
lda (MOD6_BUF),Y ; Get MOD6_BUF[0]
jmp send_mod6_char ; Send MOD6_BUF[0] and RTS
;-------------------------------------------------------------------------------
; MOD6_ACTION = 1 : Received data address from PLATO. Save address to pointer.
;-------------------------------------------------------------------------------
mod6_s1:
sty MOD6_BUF+1 ; MOD6_BUF = PLATO_WORD
sta MOD6_BUF ;
jmp mod6_terminate ; Send response and RTS
;-------------------------------------------------------------------------------
; MOD6_ACTION = 3 : Received subroutine address from PLATO. Save address to pointer.
;-------------------------------------------------------------------------------
mod6_s3:
sty MOD6A+1 ; MOD6A = PLATO_WORD
sta MOD6A ;
dex ; X = $FF
stx SEND_FLG ; SEND_FLG = $FF (Yes send something)
jmp mod6_terminate ; Send response and RTS
;-------------------------------------------------------------------------------
; MOD6_ACTION = 4 : Received call address from PLATO. Save it & run it
;-------------------------------------------------------------------------------
mod6_s4:
sty MOD6A+1 ; MOD6A = PLATO_WORD
sta MOD6A ;
jsr mod6_terminate ; Send response and...
jmp (MOD6A) ; Run it (and presumably RTS)
;-------------------------------------------------------------------------------
; MOD6_ACTION = 2 : Save PLATO_WORD to MOD6_BUF (up to 2 bytes at a time)
; Subsequent visits append to buffer.
;-------------------------------------------------------------------------------
mod6_s2:
bit MOD6_1ST ; Overflow tripped if not first visit.
bmi :+ ; $FF? Yes -->
; First visit. PLATO_WORD contains expected count. Save it to MOD6_N.
sta MOD6_N ; MOD6_N = PLATO_WORD
sty MOD6_N+1 ;
dex ; X is now $FF
stx MOD6_1ST ; $FF. Will trip Overflow next time.
rts ; Quit
; Subsequent visit. Save PLATO_WORD+1 to MOD6_BUF
: tya ; A = PLATO_WORD+1
ldy #$00 ; Y = 0
sta (MOD6_BUF),Y ; Save PLATO_WORD+1 to MOD6_BUF[n]
iny ; Y = 1
; Decrement MOD6_N
dec MOD6_N ;
bne :+ ;
tya ; Advance pointer by 1
ldx MOD6_N+1 ;
beq mod6_fin ; MOD6_N reached 0? -->
dec MOD6_N+1 ;
; If expected count not to zero yet, then
; save PLATO_WORD to MOD6_BUF