; IPL command hipl equ 0fe03h ; IPLコマンドフックアドレス frmqnt equ 542fh ; 式を2バイト整数で評価 chput equ 0a2h ; 1文字出力 chrgtr equ 4666h ; コマンドラインから1文字取り出す snsmat equ 0141h ; キーマトリックスのスキャン kilbuf equ 0156h ; キーバッファクリア latch equ 0a0h ; PSGアドレスラッチ write equ 0a1h ; データライト read equ 0a2h ; データリード org 0e000h ld bc,5 ld de,hipl ld hl,hookcmd ldir ret hookcmd: jp iplmain nop nop command: defs 1 file1: defs 13 file2: defs 13 addr1: defs 2 addr2: defs 2 addrflg: defs 1 error: defs 2 portb: defs 1 portset: defs 1 iplmain: pop bc ld (error),bc ; エラー処理アドレス保存 xor a ld (command),a ld (file1),a ld (file2),a ld (addrflg),a ; 0..未設定 1..addr1設定済 2..addr2も設定 dec hl ; 最初の1文字目の位置に戻す cmdloop: call chrgtr ; コマンドライン読み取りループ jr z,cmdcheck cp 20h ; 0B〜1Fは数値の識別コード jr c,evaluat cp '"' jr z,getname cp ',' jr z,cmdloop ; カンマは無視 ld (command),a jr cmdloop getname: ld a,(file1) or a jr nz,skip1st ld bc,file1 jr skip2nd skip1st: ld a,(file2) or a jp nz,errexit ld bc,file2 skip2nd: ld d,13 ; SDファイル名は8文字+'.'+3文字 getloop: call chrgtr cp '"' jr z,setnull ld (bc),a inc bc dec d ld a,d or a jp z,errexit jr getloop setnull: xor a ld (bc),a ; 文字列の終端セット jr cmdloop evaluat: call frmqnt ld a,(addrflg) or a jr nz,skipadd1 ; addr1は設定済み ld (addr1),de ld a,1 ld (addrflg),a ; addr1を設定した jr cmdloop skipadd1: cp 1 jp nz,errexit ; addr2まで設定してある ld (addr2),de ld a,2 ld (addrflg),a jr cmdloop cmdcheck: ld a,(command) cp 'F' jr z,files cp 'L' jr z,load cp 'S' jr z,save cp 'R' jp z,rename cp 'K' jp z,kill jp errexit files: call init_out ld bc,command call outbyte ; Fコマンド送信 call end_out call init_in loop_f: call inbyte ; ファイル一覧の文字列受信 or a jr z,endfiles call chput ; 1文字表示 call pause ; SPACEキーで一時停止 jr loop_f endfiles: call end_in ret pause: ld a,8 call snsmat and 1 ret nz ; SPACEキーが押されているか norelease: ld a,8 call snsmat and 1 jr z,norelease ; SPACEキーを離したか push hl call kilbuf ; キーバッファクリア pop hl ret load: ld a,(file1) or a jp z,errexit ; ファイル名が入力されていない call init_out ld bc,command call outbyte ; Lコマンド送信 ld bc,file1 loop_l: call outbyte inc bc ld a,(bc) or a jr nz,loop_l ; ファイル名の終端チェック call outbyte ; 終端文字も送る call end_out ret save: ld a,(file1) or a jp z,errexit ; ファイル名が入力されていない ld a,(addrflg) cp 2 jp nz,errexit ; アドレスが2つ入力されていない call init_out ld bc,command call outbyte ; Sコマンド送信 ld bc,file1 loop_s: call outbyte inc bc ld a,(bc) or a jr nz,loop_s ; ファイル名の終端チェック call outbyte ; 終端文字も送る ld bc,addr1 call outbyte inc bc call outbyte ld bc,addr2 call outbyte inc bc call outbyte ret rename: ld a,(file1) or a jp z,errexit ; 旧ファイル名が入力されていない ld a,(file2) or a jp z,errexit ; 新ファイル名が入力されていない call init_out ld bc,command call outbyte ; Rコマンド送信 ld bc,file1 call loop_r ld bc,file2 call loop_r ret loop_r: call outbyte inc bc ld a,(bc) or a jr nz,loop_r ; ファイル名の終端チェック call outbyte ; 終端文字も送る ret kill: ld a,(file1) or a jp z,errexit ; ファイル名が入力されていない call init_out ld bc,command call outbyte ; Kコマンド送信 ld bc,file1 loop_k: call outbyte inc bc ld a,(bc) or a jr nz,loop_k ; ファイル名の終端チェック call outbyte ; 終端文字も送る call end_out ret errexit: ld bc,(error) push bc ; エラー処理アドレス復元 ret init_out: di ld a,0fh out (latch),a ; 汎用入出力ポートB選択 in a,(read) ld (portb),a ; ポートBの状態保存 or 40h out (write),a ; 汎用入出力インターフェイス2と接続 ld (portset),a ; ポートB設定値の保存 and 0dfh ; 8ピンをLOW out (write),a ; 8ピン出力 ei ret end_out: di ld a,0fh out (latch),a ; 汎用入出力ポートB選択 ld a,(portb) out (write),a ; ポートBの状態復元 ei ret outbyte: di ld a,0fh out (latch),a ; 汎用入出力ポートB選択 ld a,(portset) or 20h ; 8ピンをHIGH スタートビット out (write),a ; 8ピン出力 ld a,0eh out (latch),a ; 汎用入出力ポートA選択 waitrep: in a,(read) ; ポートAから入力 and 1 ; 1ピンの値を確認 jr nz,waitrep ; 送信許可待ち(PULLUPなのでLOW待ち) ld a,0fh out (latch),a ; 汎用入出力ポートB選択 ld a,(portset) and 0dfh ; 8ピンをLOW out (write),a ; 8ピン出力 call wait ld a,(portset) and 0f3h ; 汎用入出力6,7ピンをLOW ld e,a ; ポートBの状態をeレジスタに保存 ld a,(bc) ; 出力データ ld d,a ; 出力データをdレジスタに保存 and 3 ; データの0,1ビットを残す rlca ; データの0,1ビットをシフトして汎用入出力 rlca ; 6,7ピン(ポートBの2,3ビット)にセット add a,e ; ポートBの状態復元+出力2ビット or 20h ; 8ピンをHIGH out (write),a ; データ出力 call wait ld a,e ; ポートBの状態復元 and 0dfh ; 8ピンをLOW out (write),a ; 8ピン出力 call wait ld a,d ; 出力データを復元 and 0ch ; データの2,3ビットを残す add a,e ; ポートBの状態復元+出力2ビット or 20h ; 8ピンをHIGH out (write),a ; データ出力 call wait ld a,e ; ポートBの状態復元 and 0dfh ; 8ピンをLOW out (write),a ; 8ピン出力 call wait ld a,d ; 出力データを復元 rrca ; データの4,5ビットをシフトして汎用入出力 rrca ; 6,7ピン(ポートBの2,3ビット)にセット ld d,a ; 2ビットずらしたデータを保存しておく and 0ch ; データの2,3ビットを残す add a,e ; ポートBの状態復元 or 20h ; 8ピンをHIGH out (write),a ; データ出力 call wait ld a,e ; ポートBの状態復元 and 0dfh ; 8ピンをLOW out (write),a ; 8ピン出力 call wait ld a,d ; 2ビットずらした出力データを復元 rrca ; データの4,5ビットをシフトして汎用入出力 rrca ; 6,7ピン(ポートBの2,3ビット)にセット and 0ch ; データの2,3ビットを残す add a,e ; ポートBの状態復元 or 20h ; 8ピンをHIGH out (write),a ; データ出力 call wait ld a,e ; ポートBの状態復元 and 0dfh ; 8ピンをLOW out (write),a ; 8ピン出力 call wait ld a,0eh out (latch),a ; 汎用入出力ポートA選択 waitend: in a,(read) ; ポートAから入力 and 1 ; 1ピンの値を確認 jr z,waitend ; 受信確認(HIGH待ち) ei ret init_in: di ld a,0fh out (latch),a ; 汎用入出力ポートB選択 in a,(read) ld (portb),a ; ポートBの状態保存 or 40h out (write),a ; 汎用入出力インターフェイス2と接続 ld (portset),a ; ポートB設定値の保存 and 0dfh ; 8ピンをLOW out (write),a ; 8ピン出力 ei ret end_in: di ld a,0fh out (latch),a ; 汎用入出力ポートB選択 ld a,(portb) out (write),a ; ポートBの状態復元 ei ret inbyte: di ld a,0eh out (latch),a ; 汎用入出力ポートA選択 inloop: in a,(read) ; ポートAから入力 and 10h ; 6ピンのLOW待ち 送信可能 jr nz,inloop ld a,0fh out (latch),a ; 汎用入出力ポートB選択 ld a,(portset) ld c,a ; ポートB設定値の一時保存 or 20h ; 8ピンをHIGH out (write),a ; 8ピン出力 call wait ld a,c ; ポートB設定値の復元 and 0dfh ; 8ピンをLOW out (write),a ; 8ピン出力 ld a,0eh out (latch),a ; 汎用入出力ポートA選択 in a,(read) ; ポートAから入力 and 0fh rlca rlca rlca rlca ; 4ビットシフト ld b,a ; 4ビットのデータ保存 ld a,0fh out (latch),a ; 汎用入出力ポートB選択 ld a,c ; ポートB設定値の復元 or 20h ; 8ピンをHIGH 送信要求 out (write),a ; 8ピン出力 call wait ld a,c ; ポートB設定値の復元 and 0dfh ; 8ピンをLOW out (write),a ; 8ピン出力 ld a,0eh out (latch),a ; 汎用入出力ポートA選択 in a,(read) and 0fh add a,b ; バイトデータを復元 ei ret ; 約1.2ms wait: ld a,255 wloop: dec a jr nz,wloop ret ; 約2.2ms ;wait: push bc ; ld bc,100h ;165hなら 3ms ;wloop: dec bc ; ld a,b ; or c ; jr nz,wloop ; pop bc ; ret