|
4 | 4 | .include "rp6502.inc" |
5 | 5 |
|
6 | 6 | .export V_INPT, V_OUTP, V_LOAD, V_SAVE |
| 7 | +.import LAB_14BD, LAB_EVEX, LAB_SNER, LAB_22B6, LAB_1463, LAB_RMSG |
| 8 | +.importzp Dtypef, ptr1, tmp1 |
| 9 | + |
| 10 | +.data |
| 11 | + |
| 12 | +fd_in: |
| 13 | + .byte $FF ; input file descriptor, or negative for ACIA |
| 14 | +fd_out: |
| 15 | + .byte $FF ; output file descriptor, or negative for ACIA |
| 16 | + |
| 17 | +.code |
7 | 18 |
|
8 | | -V_OUTP: ; byte out to simulated ACIA |
9 | | - BIT RIA_READY |
10 | | - BPL V_OUTP ; wait for FIFO |
11 | | - STA RIA_TX ; save byte to simulated ACIA |
12 | | - RTS |
13 | 19 | V_INPT: ; byte in from simulated ACIA |
| 20 | + BIT fd_in ; check for read fd |
| 21 | + BPL read ; use read() handler |
14 | 22 | BIT RIA_READY |
15 | 23 | BVC LAB_nobyw ; branch if no byte waiting |
16 | 24 | LDA RIA_RX ; get byte from simulated ACIA |
17 | 25 | SEC ; flag byte received |
18 | 26 | RTS |
19 | 27 | LAB_nobyw: |
20 | 28 | CLC ; flag no byte received |
| 29 | + RTS |
| 30 | +read: |
| 31 | + LDA tmp1 |
| 32 | + BEQ read_read |
| 33 | + DEC tmp1 |
| 34 | + LDA #$0D |
| 35 | + SEC |
| 36 | + RTS |
| 37 | +read_read: |
| 38 | + LDA #$01 |
| 39 | + STA RIA_XSTACK |
| 40 | + LDA fd_in |
| 41 | + STA RIA_A |
| 42 | + LDA #RIA_OP_READ_XSTACK |
| 43 | + STA RIA_OP ; int read_xstack(void *buf, unsigned count, int fildes) |
| 44 | +read_busy: |
| 45 | + BIT RIA_BUSY |
| 46 | + BMI read_busy |
| 47 | + LDA RIA_XSTACK |
| 48 | + CMP #$0A ; LF and CRLF endings supported |
| 49 | + BEQ read_cr |
| 50 | + CMP #$00 ; empty stack always returns 0 |
| 51 | + BNE read_done |
| 52 | + LDA fd_in ; eof |
| 53 | + STA RIA_A |
| 54 | + LDA #RIA_OP_CLOSE |
| 55 | + STA RIA_OP ; int close(int fildes) |
| 56 | +read_close: |
| 57 | + BIT RIA_BUSY |
| 58 | + BMI read_close |
| 59 | + LDA #$FF |
| 60 | + STA fd_in ; restore V_INPT to ACIA |
| 61 | + STA fd_out ; restore V_OUTP to ACIA |
| 62 | + PHY ; print "Ready" |
| 63 | + LDA #<(LAB_RMSG) |
| 64 | + STA ptr1 |
| 65 | + LDA #>(LAB_RMSG) |
| 66 | + STA ptr1+1 |
| 67 | + LDY #$00 |
| 68 | +read_ready_loop: |
| 69 | + LDA (ptr1),y |
| 70 | + JSR V_OUTP_wait |
| 71 | + INY |
| 72 | + CPY #$07 |
| 73 | + BMI read_ready_loop |
| 74 | + PLY |
| 75 | +read_cr: |
| 76 | + LDA #$0D |
| 77 | +read_done: |
| 78 | + SEC |
| 79 | + RTS |
| 80 | + |
| 81 | + |
| 82 | +V_OUTP: ; byte out to simulated ACIA |
| 83 | + BIT fd_out ; check for write fd |
| 84 | + BPL write ; use write() handler |
| 85 | +V_OUTP_wait: |
| 86 | + BIT RIA_READY ; check ready bit |
| 87 | + BPL V_OUTP_wait ; wait for FIFO |
| 88 | + STA RIA_TX ; save byte to simulated ACIA |
| 89 | + RTS |
| 90 | +write: |
| 91 | + BIT fd_in ; check for read fd |
| 92 | + BPL write_skip ; dump load echos to null |
| 93 | + CMP #$0D ; ASCII 13 CR |
| 94 | + BEQ write_skip ; filter CR, saves are LF only |
| 95 | + STA RIA_XSTACK |
| 96 | + LDA fd_out |
| 97 | + STA RIA_A |
| 98 | + LDA #RIA_OP_WRITE_XSTACK |
| 99 | + STA RIA_OP ; int write_xstack(const void *buf, unsigned count, int fildes) |
| 100 | +write_busy: |
| 101 | + BIT RIA_BUSY |
| 102 | + BMI write_busy ; TODO check for errors |
| 103 | +write_skip: |
| 104 | + RTS |
| 105 | + |
| 106 | + |
21 | 107 | V_LOAD: ; empty load vector for EhBASIC |
22 | | -V_SAVE: ; empty save vector for EhBASIC |
| 108 | + LDA #$01 ; O_RDONLY |
| 109 | + JSR open |
| 110 | + BMI syntax_error ; TODO file error instead of syntax |
| 111 | + STA fd_in ; redirect V_INPT from fd |
| 112 | + STA fd_out ; redirect V_OUTP to null |
| 113 | + TSX ; LAB_NEW clobbers stack, save the return |
| 114 | + INX |
| 115 | + LDA $100,X |
| 116 | + STA ptr1 |
| 117 | + INX |
| 118 | + LDA $100,X |
| 119 | + STA ptr1+1 |
| 120 | + JSR LAB_1463 ; LAB_NEW |
| 121 | + LDA ptr1+1 ; restore the return address clobbered by new |
| 122 | + PHA |
| 123 | + LDA ptr1 |
| 124 | + PHA |
| 125 | + LDA #$01 ; preamble newlines |
| 126 | + STA tmp1 |
| 127 | + RTS |
| 128 | + |
| 129 | + |
| 130 | +V_SAVE: |
| 131 | + LDA #$32 ; O_TRUNC | O_CREAT | O_WRONLY |
| 132 | + JSR open |
| 133 | + BMI syntax_error ; TODO file error instead of syntax |
| 134 | + STA fd_out ; redirect V_OUTP to fd |
| 135 | + JSR LAB_14BD ; LAB_LIST |
| 136 | + LDA fd_out |
| 137 | + STA RIA_A ; to be used by close() |
| 138 | + LDA #$FF |
| 139 | + STA fd_out ; restore V_OUTP to ACIA |
| 140 | + LDA #RIA_OP_CLOSE |
| 141 | + STA RIA_OP ; int close(int fildes) |
| 142 | + JSR RIA_SPIN |
| 143 | + BMI syntax_error ; TODO file error instead of syntax |
23 | 144 | RTS |
| 145 | + |
| 146 | + |
| 147 | +open: |
| 148 | + STA RIA_A ; file open options |
| 149 | + JSR LAB_EVEX ; evaluate expression |
| 150 | + LDA Dtypef ; data type flag, $FF=string, $00=numeric |
| 151 | + BEQ syntax_error ; syntax error if not string |
| 152 | + JSR LAB_22B6 ; obtain string |
| 153 | + STX ptr1 ; pointer low byte |
| 154 | + STY ptr1+1 ; pointer high byte |
| 155 | + TAY ; length |
| 156 | + BEQ syntax_error ; syntax error if empty string |
| 157 | +push_filename: |
| 158 | + DEY |
| 159 | + LDA (ptr1), Y |
| 160 | + STA RIA_XSTACK |
| 161 | + TYA |
| 162 | + BNE push_filename |
| 163 | + LDA #RIA_OP_OPEN |
| 164 | + STA RIA_OP ; int open(const char *path, int oflag) |
| 165 | + JMP RIA_SPIN |
| 166 | + |
| 167 | + |
| 168 | +syntax_error: |
| 169 | + JMP LAB_SNER ; far jump |
0 commit comments