prodos-drivers/b.s

566 lines
12 KiB
ArmAsm
Raw Normal View History

2017-12-09 17:03:44 +00:00
;;; Disassembly of BYE.SYSTEM (Bird's Better Bye)
2017-11-12 04:44:15 +00:00
.setcpu "65C02"
2017-12-09 17:03:44 +00:00
.include "apple2.inc"
2017-11-12 04:44:15 +00:00
.include "prodos.inc"
L0060 := $0060
RAMRDOFF := $C002
RAMRDON := $C003
RAMWRTOFF := $C004
RAMWRTON := $C005
ALTZPOFF := $C008
ALTZPON := $C009
ROMINNW := $C082
ROMINWB1 := $C089
LC300 := $C300
MON_SETTXT := $FB39
MON_TABV := $FB5B
SETPWRC := $FB6F
BELL1 := $FBDD
MON_HOME := $FC58
COUT := $FDED
SETINV := $FE80
SETNORM := $FE84
2017-12-09 17:03:44 +00:00
ZP_HPOS := $24
ASCII_TAB := $9
ASCII_DOWN := $A
ASCII_UP := $B
ASCII_RETURN := $D
ASCII_ESCAPE := $1B
;;; ------------------------------------------------------------
.define HI(char) (char|$80)
.macro HIASCII arg
.repeat .strlen(arg), i
.byte .strat(arg, i) | $80
.endrep
.endmacro
.macro HIASCIIZ arg
HIASCII arg
.byte 0
.endmacro
;;; ------------------------------------------------------------
;; Loads at $2000 but executed at $1000.
2017-11-13 15:57:57 +00:00
2017-11-12 04:44:15 +00:00
.org $2000
L2000: jmp install_and_quit
install_src := *
.org $1000
.proc bbb
2017-11-13 15:57:57 +00:00
prefix := $280 ; length-prefixed
;; filenames at $1400 - each is length byte + 15 byte buffer
read_buffer := $2000 ; Also, start location for launched SYS files
2017-12-09 17:03:44 +00:00
current_entry := $67
num_entries := $68
rows_per_screen := 21
current_line := $73
2017-11-12 04:44:15 +00:00
cld
lda ROMINNW
stz $03F2
lda #$10
sta $03F3
jsr SETPWRC
lda #$A0
jsr LC300
ldx #$17
L1016: stz $BF58,x
dex
bpl L1016
inc $BF6F
lda #$CF
sta $BF58
lda #$02
sta L0060
ldx $BF31
stx $65
lda $BF30
bne L1042
L1032: ldx $65
lda $BF32,x
cpx #$01
bcs L103F
ldx $BF31
inx
L103F: dex
stx $65
L1042: sta on_line_params_unit
MLI_CALL ON_LINE, on_line_params
bcs L1032
stz $6B
2017-11-13 15:57:57 +00:00
lda prefix+1
2017-11-12 04:44:15 +00:00
and #$0F
beq L1032
adc #$02
tax
2017-11-13 15:57:57 +00:00
L1059: stx prefix ; truncate prefix to length x
lda #'/'
sta prefix+1
sta prefix,x
stz prefix+1,x
2017-11-12 04:44:15 +00:00
MLI_CALL OPEN, open_params
bcc L107F
lda $6B
beq L1032
jsr BELL1
jsr L11DA
2017-11-13 15:57:57 +00:00
stx prefix
2017-11-12 04:44:15 +00:00
jmp keyboard_loop
2017-11-13 15:57:57 +00:00
L107F: inc $6B ; ???
2017-12-09 17:03:44 +00:00
stz num_entries
2017-11-12 04:44:15 +00:00
lda open_params_ref_num
sta read_params_ref_num
sta $61
lda #$2B
sta read_params_request
stz read_params_request+1
2017-11-13 15:57:57 +00:00
jsr do_read
2017-11-12 04:44:15 +00:00
bcs L10B3
ldx #$03
L109A: lda $2023,x
sta $6E,x
dex
bpl L109A
sta read_params_request
lda #$01
sta $72
stz $63
stz $64
lda $70
ora $71
bne L10B5
L10B3: bra L1129
L10B5: bit $71
bmi L10B3
L10B9: lda $63
and #$FE
sta $63
ldy $72
lda #$00
cpy $6F
bcc L10CE
tay
sty $72
inc $63
L10CC: inc $63
L10CE: dey
clc
bmi L10D8
adc $6E
bcc L10CE
bcs L10CC
L10D8: adc #$04
sta $62
MLI_CALL SET_MARK, L0060
bcs L10B3
2017-11-13 15:57:57 +00:00
jsr do_read
2017-11-12 04:44:15 +00:00
bcs L10B3
inc $72
2017-11-13 15:57:57 +00:00
lda read_buffer
2017-11-12 04:44:15 +00:00
and #$F0
beq L10B9
dec $70
bne L10F8
dec $71
L10F8: ror $201E
bcc L10B5
lda $2010
cmp #$0F
beq L1108
cmp #$FF
bne L10B5
2017-12-09 17:03:44 +00:00
L1108: ldx num_entries
2017-11-12 04:44:15 +00:00
cpx #$80
bcs L1129
sta $74,x
jsr L1258
ldy #$0F
2017-11-13 15:57:57 +00:00
L1115: lda read_buffer,y
2017-11-12 04:44:15 +00:00
sta ($6C),y
dey
bpl L1115
iny
and #$0F
sta ($6C),y
2017-12-09 17:03:44 +00:00
inc num_entries
2017-11-12 04:44:15 +00:00
bne L10B5
L1126: jmp L1032
L1129: MLI_CALL CLOSE, close_params
bcs L1126
2017-12-09 17:03:44 +00:00
;; TEXT : HOME : VTAB 23
2017-11-12 04:44:15 +00:00
jsr MON_SETTXT
jsr MON_HOME
2017-12-09 17:03:44 +00:00
lda #23 ; line 23
2017-11-12 04:44:15 +00:00
jsr MON_TABV
2017-12-09 17:03:44 +00:00
;; Print help text
ldy #0
lda #20 ; HTAB 20
jsr cout_string_hpos
2017-11-12 04:44:15 +00:00
jsr L12AD
2017-12-09 17:03:44 +00:00
ldx #0
: lda prefix+1,x
2017-11-12 04:44:15 +00:00
beq L1153
jsr L12AF
inx
2017-12-09 17:03:44 +00:00
bne :-
L1153: stz current_entry
stz current_line
lda num_entries
2017-11-12 04:44:15 +00:00
beq keyboard_loop
2017-12-09 17:03:44 +00:00
cmp #rows_per_screen
2017-11-12 04:44:15 +00:00
bcc L1161
lda #$14
L1161: sta $6A
lda #$02
sta $22
sta $20
lda #$16
sta $21
sta $23
2017-12-09 17:03:44 +00:00
L116F: jsr draw_current_line
inc current_entry
2017-11-12 04:44:15 +00:00
dec $6A
bne L116F
2017-12-09 17:03:44 +00:00
stz current_entry
beq draw_current_line_inv
.proc on_up
jsr draw_current_line ; show current line
ldx current_entry
beq draw_current_line_inv
dec current_entry
2017-11-12 04:44:15 +00:00
lda $25
cmp #$02
2017-12-09 17:03:44 +00:00
bne draw_current_line_inv
dec current_line
lda #$16 ; code output ???
bne draw_current_line_with_char
.endproc
2017-11-12 04:44:15 +00:00
2017-12-09 17:03:44 +00:00
.proc on_down
jsr draw_current_line
ldx current_entry
2017-11-12 04:44:15 +00:00
inx
2017-12-09 17:03:44 +00:00
cpx num_entries
bcs draw_current_line_inv
stx current_entry
2017-11-12 04:44:15 +00:00
lda $25
2017-12-09 17:03:44 +00:00
cmp #rows_per_screen
bne draw_current_line_inv
inc current_line
lda #$17 ; code output ???
;; fall through
.endproc
draw_current_line_with_char:
jsr COUT
draw_current_line_inv:
jsr SETINV
jsr draw_current_line
;; fall through
;;; ------------------------------------------------------------
2017-11-12 04:44:15 +00:00
keyboard_loop:
lda KBD
bpl keyboard_loop
sta KBDSTRB
jsr SETNORM
2017-12-09 17:03:44 +00:00
ldx num_entries
2017-11-12 04:44:15 +00:00
beq L11CB
2017-12-09 17:03:44 +00:00
cmp #HI(ASCII_RETURN)
2017-11-13 15:57:57 +00:00
beq on_return
2017-12-09 17:03:44 +00:00
cmp #HI(ASCII_DOWN)
2017-11-12 04:44:15 +00:00
beq on_down
2017-12-09 17:03:44 +00:00
cmp #HI(ASCII_UP)
2017-11-12 04:44:15 +00:00
beq on_up
2017-12-09 17:03:44 +00:00
L11CB: cmp #HI(ASCII_TAB)
2017-11-12 04:44:15 +00:00
beq next_drive
2017-12-09 17:03:44 +00:00
cmp #HI(ASCII_ESCAPE)
2017-11-12 04:44:15 +00:00
bne keyboard_loop
jsr L11DA
dec $6B
bra L11F1
2017-11-13 15:57:57 +00:00
L11DA: ldx prefix
2017-11-12 04:44:15 +00:00
L11DD: dex
2017-11-13 15:57:57 +00:00
lda prefix,x
cmp #'/'
2017-11-12 04:44:15 +00:00
bne L11DD
cpx #$01
bne L11EC
2017-11-13 15:57:57 +00:00
ldx prefix
2017-11-12 04:44:15 +00:00
L11EC: rts
next_drive:
jmp L1032
L11F0: inx
L11F1: jmp L1059
2017-11-13 15:57:57 +00:00
on_return:
MLI_CALL SET_PREFIX, set_prefix_params
2017-11-12 04:44:15 +00:00
bcs next_drive
2017-12-09 17:03:44 +00:00
ldx current_entry
2017-11-12 04:44:15 +00:00
jsr L1258
2017-11-13 15:57:57 +00:00
ldx prefix
: iny
2017-11-12 04:44:15 +00:00
lda ($6C),y
inx
2017-11-13 15:57:57 +00:00
sta prefix,x
2017-11-12 04:44:15 +00:00
cpy $69
2017-11-13 15:57:57 +00:00
bcc :-
stx prefix
2017-12-09 17:03:44 +00:00
ldy current_entry
2017-11-12 04:44:15 +00:00
lda $74,y
2017-11-13 15:57:57 +00:00
bpl L11F0 ; is directory???
2017-12-09 17:03:44 +00:00
;;; ------------------------------------------------------------
2017-11-13 15:57:57 +00:00
.proc launch_sys_file
2017-11-12 04:44:15 +00:00
jsr MON_SETTXT
jsr MON_HOME
2017-11-13 15:57:57 +00:00
lda #$95 ; Right arrow
2017-11-12 04:44:15 +00:00
jsr COUT
2017-11-13 15:57:57 +00:00
2017-11-12 04:44:15 +00:00
MLI_CALL OPEN, open_params
bcs next_drive
lda open_params_ref_num
sta read_params_ref_num
2017-11-13 15:57:57 +00:00
lda #$FF ; Load up to $FFFF bytes
2017-11-12 04:44:15 +00:00
sta read_params_request
sta read_params_request+1
2017-11-13 15:57:57 +00:00
jsr do_read
2017-11-12 04:44:15 +00:00
php
MLI_CALL CLOSE, close_params
plp
bcs next_drive
2017-11-13 15:57:57 +00:00
jmp read_buffer ; Invoke the loaded code
.endproc
2017-11-12 04:44:15 +00:00
2017-12-09 17:03:44 +00:00
;;; ------------------------------------------------------------
cout_string_hpos:
sta ZP_HPOS
2017-11-13 15:57:57 +00:00
cout_string:
lda help_string,y
2017-11-12 04:44:15 +00:00
beq L1257
jsr COUT
iny
2017-11-13 15:57:57 +00:00
bne cout_string
2017-11-12 04:44:15 +00:00
L1257: rts
L1258: stz $6D
txa
asl a
rol $6D
asl a
rol $6D
asl a
rol $6D
asl a
rol $6D
sta $6C
lda #$14
clc
adc $6D
sta $6D
ldy #$00
lda ($6C),y
sta $69
rts
2017-12-09 17:03:44 +00:00
draw_current_line:
lda #$02
2017-11-12 04:44:15 +00:00
sta $057B
2017-12-09 17:03:44 +00:00
ldx current_entry
2017-11-12 04:44:15 +00:00
txa
sec
2017-12-09 17:03:44 +00:00
sbc current_line
2017-11-12 04:44:15 +00:00
inc a
inc a
jsr MON_TABV
lda $74,x
bmi L1299
stz $057B
lda $32
pha
2017-11-13 15:57:57 +00:00
ldy #(folder_string - string_start) ; Draw folder glyphs
jsr cout_string
2017-11-12 04:44:15 +00:00
pla
sta $32
L1299: jsr L12A9
jsr L1258
L129F: iny
lda ($6C),y
jsr L12AF
cpy $69
bcc L129F
L12A9: lda #$A0
bne L12B1
L12AD: lda #$99
L12AF: ora #$80
L12B1: jmp COUT
2017-12-09 17:03:44 +00:00
;;; ------------------------------------------------------------
2017-11-13 15:57:57 +00:00
.proc do_read
MLI_CALL READ, read_params
2017-11-12 04:44:15 +00:00
rts
2017-11-13 15:57:57 +00:00
.endproc
2017-11-12 04:44:15 +00:00
2017-12-09 17:03:44 +00:00
;;; ------------------------------------------------------------
2017-11-12 04:44:15 +00:00
2017-11-13 15:57:57 +00:00
string_start := *
2017-11-12 04:44:15 +00:00
.proc help_string
2017-12-09 17:03:44 +00:00
HIASCIIZ "RETURN: Select | TAB: Chg Vol | ESC: Back"
2017-11-12 04:44:15 +00:00
.endproc
;; Mousetext sequence: Enable, folder left, folder right, disable
.proc folder_string
.byte $0F,$1B,$D8,$D9,$18,$0E
.byte 0 ; null terminated
.endproc
2017-12-09 17:03:44 +00:00
;;; ------------------------------------------------------------
2017-11-12 04:44:15 +00:00
.proc open_params
params: .byte 3
2017-11-13 15:57:57 +00:00
path: .addr prefix
2017-11-12 04:44:15 +00:00
buffer: .addr $1C00
ref_num:.byte 0
.endproc
open_params_ref_num := open_params::ref_num
.proc close_params
params: .byte 1
ref_num:.byte 0
.endproc
.proc on_line_params
params: .byte 2
unit: .byte $60
2017-11-13 15:57:57 +00:00
buffer: .addr prefix+1
2017-11-12 04:44:15 +00:00
.endproc
on_line_params_unit := on_line_params::unit
.proc set_prefix_params
params: .byte 1
2017-11-13 15:57:57 +00:00
path: .addr prefix
2017-11-12 04:44:15 +00:00
.endproc
.proc read_params
params: .byte 4
ref_num:.byte 1
2017-11-13 15:57:57 +00:00
buffer: .word read_buffer
2017-11-12 04:44:15 +00:00
request:.word 0
trans: .word 0
.endproc
read_params_ref_num := read_params::ref_num
read_params_request := read_params::request
2017-12-09 17:03:44 +00:00
;;; ------------------------------------------------------------
2017-11-12 04:44:15 +00:00
.res 192, 0
.byte $00,$00,$00,$00,$00,$00,$00,$00
.byte $00,$00,$00,$00,$00,$00,$00,$00
.byte $00,$00,$00,$00,$00,$00,$00,$00
.byte $00,$00,$00,$00,$00,$00,$00,$00
.byte $00,$00,$00,$00,$00,$00,$00,$00
.byte $00,$00,$00,$00,$00,$00,$00,$00
.byte $00,$00,$00,$00,$00,$00,$00,$00
.byte $00,$00,$48,$AD
.endproc
.assert .sizeof(bbb) = $3FF, error, "Expected size is $3FF"
.org $2402
2017-12-09 17:03:44 +00:00
;;; ------------------------------------------------------------
.proc install_and_quit
2017-11-12 04:44:15 +00:00
jsr install
2017-12-09 17:03:44 +00:00
MLI_CALL QUIT, params
.proc params
2017-11-12 04:44:15 +00:00
params: .byte 4
type: .byte 0
res1: .word 0
res2: .byte 0
res3: .addr 0
.endproc
2017-12-09 17:03:44 +00:00
.endproc
;;; ------------------------------------------------------------
2017-11-12 04:44:15 +00:00
.proc install
src := install_src
end := install_src + .sizeof(bbb)
dst := $D100 ; Install location in ProDOS
src_ptr := $19
dst_ptr := $1B
sta ALTZPOFF
lda ROMIN
lda ROMIN
lda #>src
sta src_ptr+1
lda #<src
sta src_ptr
lda #>dst
sta dst_ptr+1
lda #<dst
sta dst_ptr
loop: lda (src_ptr)
sta (dst_ptr)
inc src_ptr
bne :+
inc src_ptr+1
: inc dst_ptr
bne :+
inc dst_ptr+1
: lda src_ptr+1
cmp #>end
bne loop
lda src_ptr
cmp #<end
bne loop
lda (src_ptr) ; WTF??
sta (dst_ptr)
sta ALTZPOFF
sta ROMINWB1
sta ROMINWB1
rts
.endproc