You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

273 lines
5.7KB

  1. .PAG 'OPEN FILE'
  2. ;***********************************
  3. ;* *
  4. ;* OPEN FUNCTION *
  5. ;* *
  6. ;* CREATES AN ENTRY IN THE LOGICAL *
  7. ;* FILES TABLES CONSISTING OF *
  8. ;* LOGICAL FILE NUMBER--LA, DEVICE *
  9. ;* NUMBER--FA, AND SECONDARY CMD-- *
  10. ;* SA. *
  11. ;* *
  12. ;* A FILE NAME DESCRIPTOR, FNADR & *
  13. ;* FNLEN ARE PASSED TO THIS ROUTINE*
  14. ;* *
  15. ;***********************************
  16. ;
  17. NOPEN LDX LA ;CHECK FILE #
  18. BNE OP98 ;IS NOT THE KEYBOARD
  19. ;
  20. JMP ERROR6 ;NOT INPUT FILE...
  21. ;
  22. OP98 JSR LOOKUP ;SEE IF IN TABLE
  23. BNE OP100 ;NOT FOUND...O.K.
  24. ;
  25. JMP ERROR2 ;FILE OPEN
  26. ;
  27. OP100 LDX LDTND ;LOGICAL DEVICE TABLE END
  28. CPX #10 ;MAXIMUM # OF OPEN FILES
  29. BCC OP110 ;LESS THAN 10...O.K.
  30. ;
  31. JMP ERROR1 ;TOO MANY FILES
  32. ;
  33. OP110 INC LDTND ;NEW FILE
  34. LDA LA
  35. STA LAT,X ;STORE LOGICAL FILE #
  36. LDA SA
  37. ORA #$60 ;MAKE SA AN SERIAL COMMAND
  38. STA SA
  39. STA SAT,X ;STORE COMMAND #
  40. LDA FA
  41. STA FAT,X ;STORE DEVICE #
  42. ;
  43. ;PERFORM DEVICE SPECIFIC OPEN TASKS
  44. ;
  45. BEQ OP175 ;IS KEYBOARD...DONE.
  46. CMP #3
  47. BEQ OP175 ;IS SCREEN...DONE.
  48. BCC OP150 ;ARE CASSETTES 1 & 2
  49. ;
  50. JSR OPENI ;IS ON SERIAL...OPEN IT
  51. BCC OP175 ;BRANCH ALWAYS...DONE
  52. ;
  53. ;PERFORM TAPE OPEN STUFF
  54. ;
  55. OP150 CMP #2
  56. BNE OP152
  57. ;
  58. JMP OPN232
  59. ;
  60. OP152 JSR ZZZ ;SEE IF TAPE BUFFER
  61. BCS OP155 ;YES
  62. ;
  63. JMP ERROR9 ;NO...DEALLOCATED
  64. ;
  65. OP155 LDA SA
  66. AND #$F ;MASK OFF COMMAND
  67. BNE OP200 ;NON ZERO IS TAPE WRITE
  68. ;
  69. ;OPEN CASSETE TAPE FILE TO READ
  70. ;
  71. JSR CSTE1 ;TELL "PRESS PLAY"
  72. BCS OP180 ;STOP KEY PRESSED
  73. ;
  74. JSR LUKING ;TELL USER "SEARCHING"
  75. ;
  76. LDA FNLEN
  77. BEQ OP170 ;LOOKING FOR ANY FILE
  78. ;
  79. JSR FAF ;LOOKING FOR NAMED FILE
  80. BCC OP171 ;FOUND IT!!!
  81. BEQ OP180 ;STOP KEY PRESSED
  82. ;
  83. OP160 JMP ERROR4 ;FILE NOT FOUND
  84. ;
  85. OP170 JSR FAH ;GET ANY OLD HEADER
  86. BEQ OP180 ;STOP KEY PRESSED
  87. BCC OP171 ;ALL O.K.
  88. BCS OP160 ;FILE NOT FOUND...
  89. ;
  90. ;OPEN CASSETTE TAPE FOR WRITE
  91. ;
  92. OP200 JSR CSTE2 ;TELL "PRESS PLAY AND RECORD"
  93. BCS OP180 ;STOP KEY PRESSED
  94. LDA #BDFH ;DATA FILE HEADER TYPE
  95. JSR TAPEH ;WRITE IT
  96. ;
  97. ;FINISH OPEN FOR TAPE READ/WRITE
  98. ;
  99. OP171 LDA #BUFSZ-1 ;ASSUME FORCE READ
  100. ;
  101. LDY SA
  102. CPY #$60 ;OPEN FOR READ?
  103. BEQ OP172
  104. ;
  105. ;SET POINTERS FOR BUFFERING DATA
  106. ;
  107. LDY #0
  108. LDA #BDF ;TYPE FLAG FOR BLOCK
  109. STA (TAPE1)Y ;TO BEGIN OF BUFFER
  110. TYA
  111. ;
  112. OP172 STA BUFPT ;POINT TO DATA
  113. OP175 CLC ;FLAG GOOD OPEN
  114. OP180 RTS ;EXIT IN PEACE
  115. .SKI 5
  116. OPENI LDA SA
  117. BMI OP175 ;NO SA...DONE
  118. ;
  119. LDY FNLEN
  120. BEQ OP175 ;NO FILE NAME...DONE
  121. ;
  122. LDA #0 ;CLEAR THE SERIAL STATUS
  123. STA STATUS
  124. ;
  125. LDA FA
  126. JSR LISTN ;DEVICE LA TO LISTEN
  127. ;
  128. LDA SA
  129. ORA #$F0
  130. JSR SECND
  131. ;
  132. LDA STATUS ;ANYBODY HOME?
  133. BPL OP35 ;YES...CONTINUE
  134. ;
  135. ;THIS ROUTINE IS CALLED BY OTHER
  136. ;KERNAL ROUTINES WHICH ARE CALLED
  137. ;DIRECTLY BY OS. KILL RETURN
  138. ;ADDRESS TO RETURN TO OS.
  139. ;
  140. PLA
  141. PLA
  142. JMP ERROR5 ;DEVICE NOT PRESENT
  143. ;
  144. OP35 LDA FNLEN
  145. BEQ OP45 ;NO NAME...DONE SEQUENCE
  146. ;
  147. ;SEND FILE NAME OVER SERIAL
  148. ;
  149. LDY #0
  150. OP40 LDA (FNADR)Y
  151. JSR CIOUT
  152. INY
  153. CPY FNLEN
  154. BNE OP40
  155. ;
  156. OP45 JMP CUNLSN ;JSR UNLSN: CLC: RTS
  157. .PAGE 'OPEN RS232 FILE'
  158. ; OPN232 - OPEN AN RS-232 OR PARALLEL PORT FILE
  159. ;
  160. ; VARIABLES INITILIZED
  161. ; BITNUM - # OF BITS TO BE SENT CALC FROM M51CTR
  162. ; BAUDOF - BAUD RATE FULL
  163. ; RSSTAT - RS-232 STATUS REG
  164. ; M51CTR - 6551 CONTROL REG
  165. ; M51CDR - 6551 COMMAND REG
  166. ; M51AJB - USER BAUD RATE (CLOCK/BAUD/2-100)
  167. ; ENABL - 6526 NMI ENABLES (1-NMI BIT ON)
  168. ;
  169. OPN232 JSR CLN232 ;SET UP RS232, .Y=0 ON RETURN
  170. ;
  171. ; PASS PRAMS TO M51REGS
  172. ;
  173. STY RSSTAT ;CLEAR STATUS
  174. ;
  175. OPN020 CPY FNLEN ;CHECK IF AT END OF FILENAME
  176. BEQ OPN025 ;YES...
  177. ;
  178. LDA (FNADR)Y ;MOVE DATA
  179. STA M51CTR,Y ;TO M51REGS
  180. INY
  181. CPY #4 ;ONLY 4 POSSIBLE PRAMS
  182. BNE OPN020
  183. ;
  184. ; CALC # OF BITS
  185. ;
  186. OPN025 JSR BITCNT
  187. STX BITNUM
  188. ;
  189. ; CALC BAUD RATE
  190. ;
  191. LDA M51CTR
  192. AND #$0F
  193. BEQ OPN028
  194. ;
  195. ; CALCULATE START-TEST RATE...
  196. ; DIFFERENT THAN ORIGINAL RELEASE 901227-01
  197. ;
  198. ASL A ;GET OFFSET INTO TABLES
  199. TAX
  200. LDA PALNTS ;GET TV STANDARD
  201. BNE OPN026
  202. LDY BAUDO-1,X ;NTSC STANDARD
  203. LDA BAUDO-2,X
  204. JMP OPN027
  205. ;
  206. OPN026 LDY BAUDOP-1,X ;PAL STANDARD
  207. LDA BAUDOP-2,X
  208. OPN027 STY M51AJB+1 ;HOLD START RATE IN M51AJB
  209. STA M51AJB
  210. OPN028 LDA M51AJB ;CALCULATE BAUD RATE
  211. ASL
  212. JSR POPEN ;GOTO PATCH AREA
  213. ;
  214. ; CHECK FOR 3/X LINE RESPONSE
  215. ;
  216. OPN030 LDA M51CDR ;BIT 0 OF M51CDR
  217. LSR A
  218. BCC OPN050 ;...3 LINE
  219. ;
  220. ; CHECK FOR X LINE PROPER STATES
  221. ;
  222. LDA D2PRB
  223. ASL A
  224. BCS OPN050
  225. JSR CKDSRX ;CHANGE FROM JMP TO PREVENT SYSTEM
  226. ;
  227. ; SET UP BUFFER POINTERS (DBE=DBS)
  228. ;
  229. OPN050 LDA RIDBE
  230. STA RIDBS
  231. LDA RODBE
  232. STA RODBS
  233. ;
  234. ; ALLOCATE BUFFERS
  235. ;
  236. OPN055 JSR GETTOP ;GET MEMSIZ
  237. LDA RIBUF+1 ;IN ALLOCATION...
  238. BNE OPN060 ;ALREADY
  239. DEY ;THERE GOES 256 BYTES
  240. STY RIBUF+1
  241. STX RIBUF
  242. OPN060 LDA ROBUF+1 ;OUT ALLOCATION...
  243. BNE MEMTCF ;ALREAY
  244. DEY ;THERE GOES 256 BYTES
  245. STY ROBUF+1
  246. STX ROBUF
  247. MEMTCF SEC ;SIGNAL TOP OF MEMORY CHANGE
  248. LDA #$F0
  249. JMP SETTOP ;TOP CHANGED
  250. ;
  251. ; CLN232 - CLEAN UP 232 SYSTEM FOR OPEN/CLOSE
  252. ; SET UP DDRB AND CB2 FOR RS-232
  253. ;
  254. CLN232 LDA #$7F ;CLEAR NMI'S
  255. STA D2ICR
  256. LDA #%00000110 ;DDRB
  257. STA D2DDRB
  258. STA D2PRB ;DTR,RTS HIGH
  259. LDA #$04 ;OUTPUT HIGH PA2
  260. ORA D2PRA
  261. STA D2PRA
  262. LDY #00
  263. STY ENABL ;CLEAR ENABLS
  264. RTS
  265. .END
  266. ; RSR 8/25/80 - ADD RS-232 CODE
  267. ; RSR 8/26/80 - TOP OF MEMORY HANDLER
  268. ; RSR 8/29/80 - ADD FILENAME TO M51REGS
  269. ; RSR 9/02/80 - FIX ORDERING OF RS-232 ROUTINES
  270. ; RSR 12/11/81 - MODIFY FOR VIC-40 I/O
  271. ; RSR 2/08/82 - CLEAR STATUS IN OPENI
  272. ; RSR 5/12/82 - COMPACT RS232 OPEN/CLOSE CODE