/
Electron-Expansion-v2.02.s65
4939 lines (4196 loc) · 134 KB
/
Electron-Expansion-v2.02.s65
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
.include "submodules/beeb/include/beeb.s65"
;-------------------------------------------------------------------------
;
; ROM zero page
;
L00A8=$A8
L00A9=$A9
L00AA=$AA
L00AB=$AB
L00AC=$AC
L00AD=$AD
wptr=$b0
L00B2=$b2
L00B3=$b3
;-------------------------------------------------------------------------
;
; OS zero page
;
os_auto_repeat_countdown=$e7 ; EAUG3 p187
os_a=$ef ; A value for osbyte/osword
os_x=$f0 ; X value for osbyte/osword
os_y=$f1 ; Y value for osbyte/osword
L00F2=$f2
L00F4=$f4
L00F6=$f6
L00F7=$f7
L00FA=$fa
L00FB=$fb
L00FC=$fc
L00FF=$ff
;-------------------------------------------------------------------------
;
; Stack regions
;
; Buffer for BRK stuff.
L0100=$100
; Various addresses in the little thunks that get copied to the stack.
; Needs rationalising - these should be expressed as offsets into the
; corresponding blocks of code.
L0138=$138
L0140=$140
L014D=$14d
L014E=$14e
L0150=$150
L0151=$151
L0152=$152
L0153=$153
L0154=$154
; Default address for joystick thunk.
default_joystick_overlay_address=$155
line_input_pblock=$150
line_input_data=$155
;-------------------------------------------------------------------------
;
; OS page 2/3
;
os_current_adc_channel=$24c
L0255=$255
os_shadow_ram_flag=$27f
os_printer_destination=$285 ; set by *FX5
; 0 = BREAK
; 1 = power on
; 2 = CTRL+BREAK
os_last_reset_type=$28d
; Flags ($0290 - unused by Electron OS)
; %.a....jj %jj = joystick interface to use
; a = 0=ADC, 1=9-pin joysticks
os_unused=$290
os_rom_types=$2a0
os_buffer_busy_flags=$2c3
L02CF=$2cf
L02D8=$2d8
os_last_adc_channel=$2f7
os_adc_lsbs=$2f8
os_adc_msbs=$2fc
os_screen_mode=$355
;-------------------------------------------------------------------------
;
; Plus One workspace
;
poll_flags=$d68
serial_baud_rates=$d69
serial_flags=$d6a
L0D6B=$D6B
L0D6C=$D6C
L0D6D=$D6D
L0D6E=$D6E
L0DDE=$dde
L0DDF=$ddf
;-------------------------------------------------------------------------
;
; ???
;
rload_ram_buffer=$2000
file_name_buffer=$156
rload_osfile_pblock=$1fe0
; L1FE3=$1fe3
; L1FEA=$1fea
; L1FEB=$1feb
; L1FEF=$1fef
;-------------------------------------------------------------------------
;
; Plus One hardware
;
LFC60=$fc60
xhw_serial_baud_rates=$fc61
LFC62=$FC62
LFC63=$FC63
LFC64=$FC64
LFC65=$FC65
LFC6D=$FC6D
LFC6E=$FC6E
LFC6F=$FC6F
; Read: 8-bit ADC result
; Write: ADC channel to convert (4 = ch1, 5 = ch2, etc.)
plus1_adc=$fc70
plus1_printer=$fc71
; Read:
; 7 6 5 4 3 2 1 0 BSY = printer busy
; +---+---+---+---+---+---+---+---+ ADC = ADC conversion end
; |BSY|ADC|FB1|FB2| | FB1 = fire button 1
; +---+---+---+---+---+---+---+---+ FB2 = fire button 2
; Write:
; (looks like there's some kind of printer strobe in bit 4)
plus1_status=$fc72
LFC73=$fc73
;-------------------------------------------------------------------------
;
; Stuff in ROM
;
default_vectors_ptr=$ffb7
; FF9C: PLA:<<restore that ROM>>:PLA:PLP:RTS
LFF9C=$ff9c
; nonsense address in the Electron OS, but presumably meaningful with
; the rombox?
LFBFD=$fbfd
;-------------------------------------------------------------------------
*=$8000
.byte 0
.byte 0
.byte 0
;-------------------------------------------------------------------------
jmp service_entry
;-------------------------------------------------------------------------
.byte $82 ; ROM type - $80 = has service entry
; $02 = 6502 code
.byte <copyright ; copyright offset
.byte 0 ; ROM version
rom_title: .text "Electron Expansion"
.byte $7F, $7F, $7F, $7F, $7F, $7F, $7F, $7F, $7F, $7F, $7F ; 0 ; as many DELs as length of ROM title
.byte $7F, $7F, $7F, $7F, $7F, $7F, $7F ; 11
.byte $B ; cursor up
.byte $B ; cursor up
.byte 0
rom_version_string:.text "2.02"
copyright:
.byte 0
rom_copyright_string:.text "(C)1988 Slogger"
.byte 0
;-------------------------------------------------------------------------
service_entry:
php
tax
cpx #$16
bcs L8057 ; taken if service >=$16
pha
asl a
tax
lda service_routines+1,x
pha
lda service_routines,x
pha
rts
;-------------------------------------------------------------------------
L8057:
ldx L00F4
plp
rts
;-------------------------------------------------------------------------
service_routines:.word svc_nop-1
.word svc_absolute_fs_space_claim-1
.word svc_nop-1
.word svc_nop-1
.word svc_star-1
.word svc_irq-1
.word svc_brk-1
.word svc_osbyte-1
.word svc_nop-1
.word svc_help-1
.word svc_nop-1
.word svc_nop-1
.word svc_nop-1
.word svc_nop-1
.word svc_nop-1
.word svc_nop-1
.word svc_nop-1
.word svc_nop-1
.word svc_nop-1
.word svc_rs423_buffer-1
.word svc_printer_buffer-1
.word svc_100Hz_poll-1
;-------------------------------------------------------------------------
svc_nop:
ldx L00F4
pla
plp
rts
;-------------------------------------------------------------------------
svc_claimed:
pla
lda #0
plp
rts
;-------------------------------------------------------------------------
svc_absolute_fs_space_claim:
tya
pha
lda #0
sta poll_flags
sta L0D6B
ldx #4
jsr set_adc_sampling_channels
lda os_last_reset_type; 0 = BREAK
; 1 = power on
; 2 = CTRL+BREAK
and #3
cmp #1
bcc L80AF ; taken if soft BREAK
ldx #1
stx os_printer_destination; set by *FX5
sec
L80AF:
jsr reset_serial
pla
tay
jmp svc_nop
;-------------------------------------------------------------------------
svc_star:
txa
pha
tya
pha
ldx #0
ldx #0
jsr find_command; Try to find command in commands table
; Entry: ($f2),y = pointer to string
; X = offset into command_table
; Exit:
bcc L80CB
pla
tay
pla
tax
jmp svc_nop
;-------------------------------------------------------------------------
L80CB:
clc
jsr call_command_table_routine; Call routine from command table
; Entry: X = offset of address in table
pla
tay
pla
tax
jmp svc_claimed
;-------------------------------------------------------------------------
L80D6:
ldx #$76
jmp do_error
;-------------------------------------------------------------------------
cmd_joystick:
bcc cmd_joystick_do
ldx #0
cmd_joystick_help:
jsr print_following_string
.byte $D
.byte $A
.text " *JOYSTICK 1-4 "
.byte 0
L80F5:
lda cmd_joystick_banner,x
beq L8100
jsr oswrch
inx
bne L80F5
L8100:
inx
lda cmd_joystick_banner,x
bne cmd_joystick_help
rts
;-------------------------------------------------------------------------
cmd_joystick_do:
jsr reset_default_vectors; Reset BYTEV and KEYV to their default values.
jsr is_string_empty ; Check if command line tail is empty.
; Entry: ($f2),y = command line tail
; Exit: C=0 - something on command line
; C=1 - nothing on command line
bcs L80D6
jsr strtoi
tax
dex
cpx #4
bcs L80D6
stx wptr
lda os_unused ; Flags ($0290 - unused by Electron OS)
; %.a....jj %jj = joystick interface to use
; a = 0=ADC, 1=9-pin joysticks
and #$FC ; clear joystick bits
ora wptr ; set joystick bits
sta os_unused ; Flags ($0290 - unused by Electron OS)
; %.a....jj %jj = joystick interface to use
; a = 0=ADC, 1=9-pin joysticks
jsr is_string_empty; Check if command line tail is empty.
; Entry: ($f2),y = command line tail
; Exit: C=0 - something on command line
; C=1 - nothing on command line
bcs L8191
tya
pha
ldx #joystick_subcommands-command_table;
jsr find_command; Try to find command in commands table
; Entry: ($f2),y = pointer to string
; X = offset into command_table
; Exit:
pla
tay
bcc L8153
ldx #0
L8136:
jsr strtoi
eor #$FF
and #$7F
sta wptr
txa
pha
lda rom_banks_table,x; table holding ROM bank numbers for 5 unused ROMs
tax
lda wptr
sta os_rom_types,x
pla
tax
inx
cpx #5
L814F:
bne L8136
beq L817A
L8153:
jsr call_command_table_routine; Call routine from command table
; Entry: X = offset of address in table
jsr print_following_string
.byte $D
.text "Overlay address : "
.byte 0
jsr read_line
lda #<default_joystick_overlay_address
sta L00F2
lda #>default_joystick_overlay_address
sta L00F2+1
ldy #0
L817A:
lda #$50
sta wptr
lda #1
sta wptr+1
jsr is_string_empty; Check if command line tail is empty.
; Entry: ($f2),y = command line tail
; Exit: C=0 - something on command line
; C=1 - nothing on command line
bcs L818E ; taken if string empty
jsr strtoi
ora wptr+1
beq L8191
L818E:
jsr L81BC
L8191:
lda os_unused ; Flags ($0290 - unused by Electron OS)
; %.a....jj %jj = joystick interface to use
; a = 0=ADC, 1=9-pin joysticks
ora #$40
sta os_unused ; Flags ($0290 - unused by Electron OS)
; %.a....jj %jj = joystick interface to use
; a = 0=ADC, 1=9-pin joysticks
rts
;-------------------------------------------------------------------------
read_line: .block
lda #<line_input_data
sta line_input_pblock+0
lda #>line_input_data
sta line_input_pblock+1
lda #5
sta line_input_pblock+2
lda #32
sta line_input_pblock+3
lda #127
sta line_input_pblock+4
ldx #<line_input_pblock
ldy #>line_input_pblock
lda #0
jmp osword
.endblock
;-------------------------------------------------------------------------
L81BC: .block
php
sei
ldy #$D
loop:
lda ram_thunk,y
sta (wptr),y
dey
bpl loop
lda wptr
sta keyv
lda wptr+1
sta keyv+1
clc
lda wptr
adc #2
sta wptr
bcc L81DD
inc wptr+1
L81DD:
lda wptr
sta bytev
lda wptr+1
sta bytev+1
plp
rts
.endblock
;-------------------------------------------------------------------------
; Reset BYTEV and KEYV to their default values.
reset_default_vectors:.block
php
sei
tya
pha
lda default_vectors_ptr
sta wptr
lda default_vectors_ptr+1
sta wptr+1
ldy #$A ; $0a = offset of BYTEV
reset_bytev_loop:
lda (wptr),y
sta $200,y
iny
cpy #$C
bne reset_bytev_loop
ldy #$28 ; $28 = offset of KEYV
reset_keyv_loop:
lda (wptr),y
sta $200,y
iny
cpy #$2A
bne reset_keyv_loop
pla
tay
plp
rts
.endblock
;-------------------------------------------------------------------------
ram_thunk:
lda #$19
; BYTEV entry point is here
; ($19 is an unused OSBYTE, so the ROM code checks for the KEYV entry that way)
php
sei
sta os_a ; A value for osbyte/osword
lda #$C
sta $fe05
jmp thunk_entry
;-------------------------------------------------------------------------
fred_offsets: .byte $C0
; offset of joystick I/O by joystick index
; (see table on p6 of Elk Expansion manual)
.byte $D0
.byte $E0
.byte $F0
;-------------------------------------------------------------------------
thunk_entry:
pla ; restore P
sta os_x ; save P
lda L00F4
pha ; save actual old ROM slot
lda #$C
sta L00F4 ; make $f4 and ROMSEL consistent
; Prepare return address
lda #>thunk_exit-1
pha
lda #<thunk_exit-1
pha
lda os_x ; restore P
pha ; save P
lda os_a ; A value for osbyte/osword
cmp #$19
beq thunked_keyv; taken if this is actually KEYV
cmp #$81
beq thunked_osbyte_81h; taken if this is OSBYTE $81
plp
jmp call_default_osbyte; Call default OSBYTE routine
;-------------------------------------------------------------------------
thunk_exit:
pha
php
txa
pha
tsx
lda $104,x
pha
lda $102,x
sta $104,x
pla
sta $102,x
pla
tax
jmp LFF9C ; FF9C: PLA:<<restore that ROM>>:PLA:PLP:RTS
;-------------------------------------------------------------------------
thunked_keyv:
plp
bvs L8266 ; taken if called by timer interrupt service (no-op)
bcc L8266 ; taken if testing SHIFT/CTRL (no-op)
jmp thunked_scan_keyboard; call as if KEYV with C=1 V=0
;-------------------------------------------------------------------------
L8266:
jmp call_default_keyv; Call default KEYV routine
;-------------------------------------------------------------------------
thunked_osbyte_81h:
plp
cpy #$80
bcc L82BF
cpx #0
beq L82B8
pha
tya
pha
txa
pha
eor #$FF
and #$7F
jsr check_joystick_key; Check if a key is "pressed" by the joystick.
; Entry: A = internal key number
; Exit: A=$ff if key pressed
; A=$00 if key not pressed
beq L8287 ; taken if key not pressed
; set X/Y as per OSBYTE $81
tax
tay
sec
pla
pla
pla
rts
;-------------------------------------------------------------------------
L8287:
pla
tax
pla
tay
pla
;-------------------------------------------------------------------------
; Call default OSBYTE routine
call_default_osbyte:.block
php ; save input P
sei
pha ; save input A
sty os_y ; save input Y
ldy #$A ; $0A = offset of BYTEV
bne call_default_vector_routine; JMP, in effect
.endblock
;-------------------------------------------------------------------------
; Call default KEYV routine
call_default_keyv:.block
php ; save input P
sei
pha ; save input A
sty os_y ; save input Y
ldy #$28 ; $28 = offset of KEYV
.endblock
call_default_vector_routine:
lda default_vectors_ptr
sta os_a ; LSB of default vector table address
lda default_vectors_ptr+1
sta os_x ; MSB of default vector table address
lda (os_a),y ; get LSB of routine
pha ; save LSB of routine
iny
lda (os_a),y ; get MSB of routise
sta os_x ; store MSB of routine
pla ; restore LSB of routine
sta os_a ; store LSB of routine
ldy os_y ; restore input Y
pla ; restore input A
plp ; restore input P
jmp (os_a) ; A value for osbyte/osword
;-------------------------------------------------------------------------
L82B8:
ldx #1
lda os_a ; A value for osbyte/osword
ldy #0
rts
;-------------------------------------------------------------------------
L82BF:
tya
eor #$FF
tay
txa
eor #$FF
tax
L82C7:
txa
pha
tya
pha
; 1 centisecond
ldy #0
ldx #1
lda #$81 ; Read key within time limit (INKEY)
; (EAUG p45)
jsr call_default_osbyte; Call default OSBYTE routine
iny ; If key pressed: Y=$01
; If key not pressed: Y=$00
bne L8300 ; taken if key pressed
jsr read_joystick_key ; Read key "pressed" by joystick
; Exit: Y=$00, C=0 - key pressed
; A = action index
; X = ASCII code
; Y=$ff, C=1 - no key pressed
iny ; If key pressed: Y=$01
; If key not pressed: Y=$00
bne L82EE ; taken if key pressed
lda #1
sta os_auto_repeat_countdown; EAUG3 p187
L82E1:
pla
tay
pla
tax
inx
bne L82C7
iny
bne L82C7
dey
sec
rts
;-------------------------------------------------------------------------
L82EE:
lda os_auto_repeat_countdown; EAUG3 p187
beq L82F6
dec os_auto_repeat_countdown; EAUG3 p187
bne L82E1
L82F6:
lda L0255 ; TODO - shouldn't this be lda #$ff?
; Presumably intended to reset the countdown timer
sta os_auto_repeat_countdown; EAUG3 p187
pla
pla
dey
sec
rts
;-------------------------------------------------------------------------
L8300:
dey
pla
pla
rts
;-------------------------------------------------------------------------
handle_digital_adval_unused:.block
cmp #$80
bne call_default_osbyte; Call default OSBYTE routine
cpx #5
bcs call_default_osbyte; Call default OSBYTE routine
pha
lda os_unused ; Flags ($0290 - unused by Electron OS)
; %.a....jj %jj = joystick interface to use
; a = 0=ADC, 1=9-pin joysticks
and #3 ; mask out joystick bits
tay
lda fred_offsets,y; offset of joystick I/O by joystick index
; (see table on p6 of Elk Expansion manual)
tay
lda $FC00,y
dex
bpl L832D
inx
ror a
ror a
bpl L8324
bcs L8329
L8324:
lsr a
lsr a
and #1
tax
L8329:
ldy #0
pla
rts
;-------------------------------------------------------------------------
L832D:
ldy #0
cpx #2
bcs L833F
dex
beq L8338
lsr a
lsr a
L8338:
and #3
tay
lda adc_values_table,y
tay
L833F:
ldx #0
pla
rts
.endblock
;-------------------------------------------------------------------------
adc_values_table:.byte 127
.byte 255
.byte 0
.byte 127
;-------------------------------------------------------------------------
thunked_scan_keyboard:
cpx #$80
bcc scan_multiple_keys; taken if scanning a range of keys
; scanning for specific key
pha ; save A
txa
pha ; save X
jsr check_joystick_key; Check if a key is "pressed" by the joystick.
; Entry: A = internal key number
; Exit: A=$ff if key pressed
; A=$00 if key not pressed
bne L835B ; taken if not pressed
pla ; restore X
tax
pla ; restore A
sec
clv
jmp call_default_keyv; Call default KEYV routine
;-------------------------------------------------------------------------
L835B:
tax ; X=$ff
pla ; discard X
pla ; restore A
rts
;-------------------------------------------------------------------------
scan_multiple_keys:
pha
tay
txa
pha
tya
sec
clv
jsr call_default_keyv; Call default KEYV routine
stx os_y ; Save key number pressed (or $ff if none)
pla ; restore input X - key to start scanning from
sta os_x
ldx #4
L8370:
jsr read_joystick; Read joystick
; Entry: X = action index
; Exit: A=$00 if bit set, A=$FF if bit clear
beq L838C ; taken if not pressed
txa ; A = action index
pha ; save action index
lda rom_banks_table,x; table holding ROM bank numbers for 5 unused ROMs
tax
lda os_rom_types,x; get key for this action
cmp os_x
bcc L838A ; taken if out of scan range
beq L838A ; TODO: Shouldn't equality be OK?
cmp os_y ; Y value for osbyte/osword
bcs L838A ; taken if >= KEYV result - but why?
sta os_y ; overwrite original result with new one
L838A:
pla ; restore action index
tax ; X = action index
L838C:
dex
bpl L8370
ldx os_y ; get KEYV result
pla
rts
;-------------------------------------------------------------------------
; Read key "pressed" by joystick
; Exit: Y=$00, C=0 - key pressed
; A = action index
; X = ASCII code
; Y=$ff, C=1 - no key pressed
read_joystick_key:.block
ldx #4
L8395:
txa ; A = action index
pha ; Save action index
jsr read_joystick; Read joystick
; Entry: X = action index
; Exit: A=$00 if bit set, A=$FF if bit clear
beq L83B2
lda rom_banks_table,x; get bank index for action index
tax
lda os_rom_types,x; get key for action
cmp #$7A
bcs L83B2 ; taken if invalid key number
tax
lda key_chars_table,x; get ASCII code for that key
beq L83B2 ; taken if not a printable key
tax ; X = ASCII code
pla ; A = action index
ldy #0 ; Y = $00
rts ; C=0
;-------------------------------------------------------------------------
L83B2:
pla ; restore action index
tax
dex
bpl L8395 ; keep going for all action indexes
ldy #$FF
sec
rts ; C=1
.endblock
;-------------------------------------------------------------------------
; Check if a key is "pressed" by the joystick.
; Entry: A = internal key number
; Exit: A=$ff if key pressed
; A=$00 if key not pressed
check_joystick_key:.block
ldx #0
; 0,1 = Second external socket on expansion module (SK2)
; 2,3 = First external socket on the expansion module (SK1)
; 4 = Disc
; 5,6 = USER applications
; 7 = Modem interface ROM
; 8,9 = Keyboard
; 10,11 = BASIC
; 12 = Expansion module operating system
; 13 = High priority slot in expansion module
; 14 = ECONET
; 15 = Reserved
; Of the two BASICs, looks like the higher priority one's type byte is filled out.
; The lower copy is presumably eliminated by the duplicate ROM detection.
cmp os_rom_types+2
beq read_joystick; read_joystick with X=0
cmp os_rom_types+3
beq L83D9 ; read_joystick with X=1
cmp os_rom_types+8
beq L83D8 ; read_joystick with X=2
cmp os_rom_types+9
beq L83D7 ; read_joystick with X=3
cmp os_rom_types+$A
bne L83EF ; read_joystick with X=4
inx
L83D7:
inx
L83D8:
inx
L83D9:
inx
.endblock
;-------------------------------------------------------------------------