home *** CD-ROM | disk | FTP | other *** search
/ Transactor / Transactor_26_1988_Transactor_Publishing.d64 / input.src (.txt) < prev    next >
Commodore BASIC  |  2023-02-26  |  9KB  |  476 lines

  1. 1000 sys 700
  2. 1010 .opt oo
  3. 1020 ;
  4. 1030 ; ***********************
  5. 1040 ; *                     *
  6. 1050 ; *  m/l input routine  *
  7. 1060 ; *   (NULL)right 1987    *
  8. 1070 ; *   garry g. kiziak   *
  9. 1080 ; *                     *
  10. 1090 ; ***********************
  11. 1100 ;
  12. 1110 *=$c000 ; origin of routines
  13. 1120 ;
  14. 1130 ; command jump table
  15. 1140 ;
  16. 1150 jmp print ; print at routine
  17. 1160 jmp input ; input routine
  18. 1170 ;
  19. 1180 ; get cursor position
  20. 1190 ;
  21. 1200 chkcom = $aefd ; check for a comma
  22. 1210 combyt = $b7f1 ; get a byte in x
  23. 1220 illqty = $b248 ; illegal quantity
  24. 1230 plot = $fff0 ; set/read cursor position
  25. 1240 xval .byte 0 ; temporary storage
  26. 1250 yval .byte 0 ; temporary storage
  27. 1260 ;
  28. 1270 getcur jsr combyt ; get column
  29. 1280 cpx #$28 ; 0<=x<=39
  30. 1290 bcs set1 ; too big
  31. 1300 stx yval
  32. 1310 txa
  33. 1320 pha
  34. 1330 jsr combyt ; get row
  35. 1340 cpx #$19 ; 0<=y<=24
  36. 1350 bcs set1 ; too big
  37. 1360 stx xval
  38. 1370 pla
  39. 1380 tay
  40. 1390 clc
  41. 1400 jmp plot ; set cursor
  42. 1410 set1 jmp illqty
  43. 1420 ;
  44. 1430 ; print at routine
  45. 1440 ;
  46. 1450 print jsr getcur
  47. 1460 jsr chkcom
  48. 1470 jmp $aaa4 ; continue with rom print
  49. 1480 ;
  50. 1490 ; wait for a keystroke
  51. 1500 ;
  52. 1510 getin = $ffe4 ; check for a keypress
  53. 1520 beg = $fb ; beginning of input field
  54. 1530 curpos = $fd ; cursor position within input field
  55. 1540 ;
  56. 1550 getkey lda ir ; get character under cursor
  57. 1560 eor #$80 ; reverse it
  58. 1570 sta ir
  59. 1580 ldy curpos ; get cursor position
  60. 1590 sta (beg),y
  61. 1600 lda #$10 ; initialize counter
  62. 1610 sta count2
  63. 1620 lda #$ff
  64. 1630 sta count1
  65. 1640 get1 jsr getin ; has a key been pressed
  66. 1650 bne get2 ; yes
  67. 1660 dec count1 ; count down
  68. 1670 bne get1 ; try again
  69. 1680 dec count2 ; count down some more
  70. 1690 bne get1 ; try again
  71. 1700 beq getkey ; flash cursor
  72. 1710 get2 rts
  73. 1720 count1 .byte 0 ; counter for flashing cursor
  74. 1730 count2 .byte 0
  75. 1740 ;
  76. 1750 ; input routine
  77. 1760 ;
  78. 1770 len = $02 ; max. no. of characters allowed
  79. 1780 ast = $03 ; address of input string
  80. 1790 lenb = $b2 ; length of optional string
  81. 1800 bst = $b3 ; address of optional string
  82. 1810 varadr = $05 ; address of variable
  83. 1820 findvar = $b08b ; find variable
  84. 1830 justf .byte 0 ; justify flag
  85. 1840 escflg .byte 0 ; escape flag
  86. 1850 iq .byte 0 ; character being entered
  87. 1860 ir .byte 0 ; character under cursor
  88. 1870 id .byte 0 ; mask for allowable inpputs
  89. 1880 ;
  90. 1890 input lda #$00
  91. 1900 sta justf ; no justfication
  92. 1910 jsr getcur ; get cursor position
  93. 1920 clc
  94. 1930 lda $d1 ; get screen address
  95. 1940 adc $d3 ; for beginning of input
  96. 1950 sta beg
  97. 1960 lda $d2
  98. 1970 adc #$00
  99. 1980 sta beg+1
  100. 1990 jsr chkcom
  101. 2000 jsr findvar ; find input variable
  102. 2010 sta varadr ; save its location
  103. 2020 sty varadr+1
  104. 2030 ldy #$02 ; move its descriptor
  105. 2040 inp1 lda (varadr),y ; to zero page
  106. 2050 sta len,y
  107. 2060 dey
  108. 2070 bpl inp1
  109. 2080 lda len
  110. 2090 beq set1
  111. 2100 jsr combyt ; get max length of input
  112. 2110 txa
  113. 2120 beq set1
  114. 2130 cpx len ; bigger than length of string
  115. 2140 beq inp1a
  116. 2150 bcc inp1a
  117. 2160 bcs set1 ; yes, too big
  118. 2170 inp1a stx len
  119. 2180 jsr combyt ; get id
  120. 2190 stx id
  121. 2200 txa ; set status registers
  122. 2210 bpl inp1c ; no optional string
  123. 2220 jsr chkcom
  124. 2230 jsr findvar ; find optional string
  125. 2240 ldy #$02
  126. 2250 inp1b lda ($47),y ; get descriptor for string
  127. 2260 sta lenb,y
  128. 2270 dey
  129. 2280 bpl inp1b
  130. 2290 inp1c jsr priast ; print default input
  131. 2300 inp1d lda #$00
  132. 2310 sta $c6 ; clear keyboard buffer
  133. 2320 sta curpos ; initial position of cursor
  134. 2330 sta escflg ; escape flag = 0
  135. 2340 inp2 ldy curpos
  136. 2350 lda (beg),y ; get character under the cursor
  137. 2360 sta iq ; save it
  138. 2370 sta ir ; temporarily
  139. 2380 inp3 jsr getkey ; get a keypress
  140. 2390 sta $d7 ; save it temporarily
  141. 2400 cmp #133 ; [f1]
  142. 2410 bne inp4
  143. 2420 lda id
  144. 2430 and #16 ; check id
  145. 2440 beq inp3 ; not allowed
  146. 2450 lda iq
  147. 2460 ldy curpos ; restore character under cursor
  148. 2470 sta (beg),y
  149. 2480 ldx #$1 ; set escape flg
  150. 2490 stx escflg
  151. 2500 jmp return
  152. 2510 inp4 cmp #32 ; [space]
  153. 2520 beq inp5
  154. 2530 cmp #160 ; [shifted-space]
  155. 2540 bne inp6
  156. 2550 inp5 lda #32 ; convert to a normal space
  157. 2560 sta $d7
  158. 2570 jmp (NULL)tit
  159. 2580 inp6 cmp #48 ; [0]
  160. 2590 bcc inp7
  161. 2600 cmp #58 ; [9]+1
  162. 2610 bcs inp7
  163. 2620 lda id
  164. 2630 and #2 ; check id
  165. 2640 beq inp12 ; not allowed
  166. 2650 jmp (NULL)tit ; [0-9]
  167. 2660 inp7 cmp #65 ; [a]
  168. 2670 bcc inp8a
  169. 2680 cmp #91 ; [z]+1
  170. 2690 bcs inp8a
  171. 2700 inp8 lda id
  172. 2710 and #1 ; check id
  173. 2720 beq inp12 ; not allowed
  174. 2730 jmp (NULL)tit ; [a-z] or [shift a-shift z]
  175. 2740 inp8a cmp #193 ; [shift a]
  176. 2750 bcc inp9
  177. 2760 cmp #219 ; [shift z]+1
  178. 2770 bcs inp9
  179. 2780 bcc inp8
  180. 2790 inp9 cmp #157 ; [cursor left]
  181. 2800 bne inp10
  182. 2810 ldy curpos
  183. 2820 beq inp3 ; can't cursor left
  184. 2830 lda iq
  185. 2840 sta (beg),y
  186. 2850 dec curpos
  187. 2860 jmp inp2
  188. 2870 inp10 cmp #29 ; [cursor right]
  189. 2880 bne inp11
  190. 2890 ldy curpos
  191. 2900 iny
  192. 2910 cpy len
  193. 2920 beq inp3 ; can't cursor right
  194. 2930 dey
  195. 2940 lda iq
  196. 2950 sta (beg),y
  197. 2960 jsr check
  198. 2970 inc curpos
  199. 2980 jmp inp2
  200. 2990 inp11 cmp #13 ; [return]
  201. 3000 beq return
  202. 3010 cmp #17 ; [cursor down]
  203. 3020 beq down
  204. 3030 cmp #145 ; [cursor up]
  205. 3040 beq up
  206. 3050 cmp #148 ; [insert]
  207. 3060 beq insert
  208. 3070 cmp #46 ; [.]
  209. 3080 beq decimal
  210. 3090 cmp #20 ; [delete]
  211. 3100 bne inp12
  212. 3110 jmp delete
  213. 3120 inp12 bit id ; special characters allowed
  214. 3130 bpl done ; no
  215. 3140 ldy #$00
  216. 3150 lda $d7
  217. 3160 inp13 cmp (bst),y ; yes
  218. 3170 bne inp14
  219. 3180 jmp (NULL)tit
  220. 3190 inp14 iny
  221. 3200 cpy lenb
  222. 3210 bne inp13
  223. 3220 done jmp inp3 ; no other keys allowed
  224. 3230 up ldx #$03
  225. 3240 .byte $2c
  226. 3250 down ldx #$02
  227. 3260 lda id
  228. 3270 and #8
  229. 3280 beq done
  230. 3290 .byte $2c
  231. 3300 return ldx #$01
  232. 3310 lda id
  233. 3320 and #64
  234. 3330 beq ret1
  235. 3340 jsr justr
  236. 3350 ret1 ldy curpos
  237. 3360 lda iq
  238. 3370 sta (beg),y
  239. 3380 lda id
  240. 3390 and #32 ; check for removing trailing spaces
  241. 3400 beq ret4 ; no
  242. 3410 ldy len
  243. 3420 dey
  244. 3430 ret2 lda (ast),y ; get character from a$
  245. 3440 cmp #32 ; is it a space
  246. 3450 bne ret3
  247. 3460 dey
  248. 3470 bpl ret2
  249. 3480 ret3 iny
  250. 3490 tya
  251. 3500 ldy #$00
  252. 3510 sta (varadr),y
  253. 3520 ret4 txa ; type of return in location 780
  254. 3530 pha
  255. 3540 jsr priast
  256. 3550 pla
  257. 3560 ldx escflg ; get escape flag
  258. 3570 rts
  259. 3580 decimal lda id ; check id
  260. 3590 and #4
  261. 3600 beq inp12 ; not allowed
  262. 3610 jsr checkd ; check for decimal point
  263. 3620 beq cant ; decimal point already entered
  264. 3630 jmp (NULL)tit
  265. 3640 cant jmp inp3
  266. 3650 insert ldy curpos
  267. 3660 lda iq
  268. 3670 sta (beg),y
  269. 3680 ldy len
  270. 3690 dey
  271. 3700 cpy curpos
  272. 3710 beq cant
  273. 3720 lda (ast),y
  274. 3730 cmp #32 ; is last character a space
  275. 3740 bne cant ; can't insert
  276. 3750 ins1 dey
  277. 3760 lda (beg),y ; get screen code
  278. 3770 pha ; save it
  279. 3780 lda (ast),y
  280. 3790 iny
  281. 3800 sta (ast),y ; move character in string
  282. 3810 pla
  283. 3820 sta (beg),y ; move character on screen
  284. 3830 dey
  285. 3840 cpy curpos
  286. 3850 bne ins1
  287. 3860 lda #32
  288. 3870 sta (ast),y ; put space in string
  289. 3880 ldx $c7
  290. 3890 beq ins2
  291. 3900 ora #$80
  292. 3910 ins2 sta (beg),y ; put space on screen
  293. 3920 jmp inp2
  294. 3930 delete ldy curpos
  295. 3940 bne del1
  296. 3950 iny ; cursor in first position
  297. 3960 cpy len ; only one character
  298. 3970 bne cant ; no, so can't delete
  299. 3980 dey ; yes, so put a space
  300. 3990 lda #32 ; in the first position
  301. 4000 sta (beg),y
  302. 4010 sta (ast),y
  303. 4020 jmp inp2
  304. 4030 del1 lda iq
  305. 4040 sta (beg),y
  306. 4050 iny ; is cursor on last character
  307. 4060 cpy len
  308. 4070 bne del2 ; no
  309. 4080 dey ; yes
  310. 4090 lda (ast),y ; get last character
  311. 4100 cmp #32 ; is it a space
  312. 4110 beq del2 ; yes
  313. 4120 inc curpos ; no
  314. 4130 del2 ldy curpos
  315. 4140 dey
  316. 4150 lda (ast),y ; get character to delete
  317. 4160 del3 iny
  318. 4170 cpy len
  319. 4180 beq del5
  320. 4190 lda (ast),y ; character to replace
  321. 4200 pha
  322. 4210 lda (beg),y
  323. 4220 dey
  324. 4230 ldx $c7
  325. 4240 beq del4
  326. 4250 ora #$80
  327. 4260 del4 sta (beg),y ; delete it on screen
  328. 4270 pla
  329. 4280 sta (ast),y ; delete it in string
  330. 4290 iny
  331. 4300 bne del3
  332. 4310 del5 dey
  333. 4320 lda #32
  334. 4330 sta (ast),y
  335. 4340 ldx $c7
  336. 4350 beq del6
  337. 4360 ora #$80
  338. 4370 del6 sta (beg),y
  339. 4380 dec curpos
  340. 4390 jmp inp2
  341. 4400 (NULL)tit jsr check
  342. 4410 ldy curpos
  343. 4420 lda $d7
  344. 4430 sta (ast),y ; put it in string
  345. 4440 bmi (NULL)t3
  346. 4450 cmp #$60
  347. 4460 bcc (NULL)t1
  348. 4470 and #$df
  349. 4480 bne (NULL)t2
  350. 4490 (NULL)t1 and #$3f
  351. 4500 (NULL)t2 jmp (NULL)t5
  352. 4510 (NULL)t3 and #$7f
  353. 4520 cmp #$7f
  354. 4530 bne (NULL)t4
  355. 4540 lda #$5e
  356. 4550 (NULL)t4 ora #$40
  357. 4560 (NULL)t5 ldx $c7
  358. 4570 beq (NULL)t6
  359. 4580 ora #$80
  360. 4590 (NULL)t6 sta (beg),y
  361. 4600 iny
  362. 4610 cpy len
  363. 4620 bne (NULL)t7
  364. 4630 dey
  365. 4640 (NULL)t7 sty curpos
  366. 4650 jmp inp2
  367. 4660 ;
  368. 4670 ; justify left
  369. 4680 ;
  370. 4690 tempm .byte 0
  371. 4700 tempn .byte 0
  372. 4710 ;
  373. 4720 justl ldy #$00
  374. 4730 sty tempm
  375. 4740 lda (ast),y
  376. 4750 cmp #32
  377. 4760 bne jus5 ; already justified
  378. 4770 jus1 iny
  379. 4780 cpy len
  380. 4790 beq jus5 ; all spaces
  381. 4800 lda (ast),y
  382. 4810 cmp #32
  383. 4820 beq jus1
  384. 4830 sty tempn ; first non-space character
  385. 4840 jus2 ldy tempm ; move left
  386. 4850 sta (ast),y
  387. 4860 inc tempn
  388. 4870 inc tempm
  389. 4880 ldy tempn
  390. 4890 cpy len
  391. 4900 beq jus3
  392. 4910 lda (ast),y
  393. 4920 bne jus2
  394. 4930 beq jus2
  395. 4940 jus3 ldy tempm ; rest are spaces
  396. 4950 lda #32
  397. 4960 jus4 sta (ast),y
  398. 4970 iny
  399. 4980 cpy len
  400. 4990 bcc jus4
  401. 5000 jus5 rts
  402. 5010 ;
  403. 5020 ; justify right
  404. 5030 ;
  405. 5040 justr ldy len
  406. 5050 dey
  407. 5060 sty tempm
  408. 5070 lda (ast),y
  409. 5080 cmp #32
  410. 5090 bne just5 ; already justified
  411. 5100 just1 dey
  412. 5110 bmi just5 ; all spaces
  413. 5120 lda (ast),y
  414. 5130 cmp #32
  415. 5140 beq just1
  416. 5150 sty tempn ; first non-space characterady.
  417. 5160 just2 ldy tempm
  418. 5170 sta (ast),y
  419. 5180 dec tempm
  420. 5190 dec tempn
  421. 5200 ldy tempn
  422. 5210 bmi just3
  423. 5220 lda (ast),y
  424. 5230 bne just2
  425. 5240 beq just2
  426. 5250 just3 ldy tempm ; rest are spaces
  427. 5260 lda #32
  428. 5270 just4 sta (ast),y
  429. 5280 dey
  430. 5290 bpl just4
  431. 5300 just5 rts
  432. 5310 ;
  433. 5320 ; print string
  434. 5330 ;
  435. 5340 priast lda $d7
  436. 5350 pha
  437. 5360 ldy yval
  438. 5370 ldx xval
  439. 5380 clc
  440. 5390 jsr plot
  441. 5400 ldy #$00
  442. 5410 pri1 lda (ast),y
  443. 5420 jsr $ffd2
  444. 5430 iny
  445. 5440 cpy len
  446. 5450 bne pri1
  447. 5460 pla
  448. 5470 sta $d7
  449. 5480 rts
  450. 5490 ;
  451. 5500 ; check justify flag
  452. 5510 ;
  453. 5520 check bit justf
  454. 5530 bmi ch1 ; already on
  455. 5540 lda id
  456. 5550 and #64
  457. 5560 beq ch1 ; not allowed
  458. 5570 jsr justl ; justify string and
  459. 5580 jsr priast ; print it
  460. 5590 lda #$80 ; set flag
  461. 5600 sta justf
  462. 5610 ch1 rts
  463. 5620 ;
  464. 5630 ; check for decimal
  465. 5640 ;
  466. 5650 checkd ldy len
  467. 5660 dey
  468. 5670 check1 lda (ast),y
  469. 5680 cmp #46
  470. 5690 beq check2 ; found one
  471. 5700 dey
  472. 5710 bpl check1
  473. 5720 lda #$01 ; no decimal point
  474. 5730 check2 rts
  475.