Advertisement
Guest User

Untitled

a guest
Jan 3rd, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.98 KB | None | 0 0
  1. ca65 V2.15 - Git b6f429f
  2. Main file : llamacalc.asm
  3. Current file: llamacalc.asm
  4.  
  5. 000000r 1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6. 000000r 1 ; LlamaCalc - a programmer's calculator for KIM (1/Uno)
  7. 000000r 1 ;
  8. 000000r 1 ; 2016-01 Scott Lawrence
  9. 000000r 1 ;
  10. 000000r 1 ; Created for the RetroChallenge RC2016-1
  11. 000000r 1 ; Scott Lawrence - yorgle@gmail.com
  12. 000000r 1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  13. 000000r 1
  14. 000000r 1 .define VERSIONH #$00
  15. 000000r 1 .define VERSIONL #$01
  16. 000000r 1 ; v 0001 - 2016-01-01 - initial version, keypad input support
  17. 000000r 1
  18. 000000r 1
  19. 000000r 1 ; define the functionality we want to use in the library
  20. 000000r 1 UseVideoDisplay0 = 1 ; video display 0
  21. 000000r 1
  22. 000000r 1 ; include our functions
  23. 000000r 1 .include "KimDefs.asm"
  24. 000000r 2 ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;
  25. 000000r 2 ; Kim OS defines
  26. 000000r 2
  27. 000000r 2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  28. 000000r 2 ; keypad
  29. 000000r 2
  30. 000000r 2 ; key presses
  31. 000000r 2 AK = $1EFE ; ROMFN: key down a=0, key up a<>0
  32. 000000r 2 GETKEY = $1F6A ; ROMFN: A>15 = bad key, otherwise, it's the key
  33. 000000r 2
  34. 000000r 2 ; key codes
  35. 000000r 2 .define KEY_NONE #$15
  36. 000000r 2 .define KEY_SPECIAL_MASK #$10
  37. 000000r 2 .define KEY_AD #$10
  38. 000000r 2 .define KEY_DA #$11
  39. 000000r 2 .define KEY_PC #$14
  40. 000000r 2 .define KEY_PL #$12
  41. 000000r 2
  42. 000000r 2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  43. 000000r 2 ; 7-seg display
  44. 000000r 2
  45. 000000r 2 SCANDS = $1F1F ; F9, FA, FB -> Display
  46. 000000r 2 POINTH = $FB
  47. 000000r 2 POINTL = $FA
  48. 000000r 2 INH = $F9
  49. 000000r 2
  50. 000000r 2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  51. 000000r 2 ; Serial TTY
  52. 000000r 2
  53. 000000r 2 GETCH = $1E5A ; ROMFN: Gets TTY char to A
  54. 000000r 2 OUTCH = $1EA0 ; ROMFN: Prints A as ASCII to TTY
  55. 000000r 2 OUTSP = $1E9E ; ROMFN: Prints ' ' to TTY
  56. 000000r 2 PRTBYT = $1E3B ; ROMFN: TTY Out A as 2 hex chars
  57. 000000r 2 PRTPNT = $1E1D ; ROMFN: Prints FB, FA to TTY
  58. 000000r 2
  59. 000000r 2
  60. 000000r 2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  61. 000000r 2 ; Video Display 0
  62. 000000r 2
  63. 000000r 2 RASTER = $4000 ; base of raster memory
  64. 000000r 2
  65. 000000r 2 ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;
  66. 000000r 2
  67. 000000r 1 .include "KimLib.asm"
  68. 000000r 2 ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;
  69. 000000r 2 ; KimLib
  70. 000000r 2 ; Standard use library functions
  71. 000000r 2 ;
  72. 000000r 2 ; 2015-12-29+
  73. 000000r 2 ; Scott Lawrence - yorgle@gmail.com
  74. 000000r 2
  75. 000000r 2 ; include this after including "KimDefines.asm"
  76. 000000r 2 ; your code should start with the label "main"
  77. 000000r 2
  78. 000000r 2 ; defineables:
  79. 000000r 2 ; UseVideoDisplay0 - turn on Video Display framebuffer at $4000
  80. 000000r 2
  81. 000000r 2
  82. 000000r 2 ; for standard, we'll start at 0100.
  83. 000000r 2 .org $0100
  84. 000100 2
  85. 000100 2
  86. 000100 2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  87. 000100 2 ; entrypoint
  88. 000100 2 ; - this is where the code will start from
  89. 000100 2 ; - we have this jump to the user's 'main'
  90. 000100 2 entrypoint:
  91. 000100 2 4C 40 01 jmp main
  92. 000103 2
  93. 000103 2
  94. 000103 2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  95. 000103 2 ; end
  96. 000103 2 ; - jump here to end everything
  97. 000103 2 end:
  98. 000103 2 00 brk
  99. 000104 2
  100. 000104 2 .if .defined(UseVideoDisplay0)
  101. 000104 2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  102. 000104 2 ; cls
  103. 000104 2 ; - clear the screen
  104. 000104 2 ; - jsr cls - fills with black
  105. 000104 2 ; - jsr fillscr - fills with the color in (A & 0x0F)
  106. 000104 2 cls:
  107. 000104 2 A9 00 lda #$00 ; a = 7 ; color
  108. 000106 2
  109. 000106 2 fillscr:
  110. 000106 2 AA tax ; x = a (store it aside)
  111. 000107 2 A0 FF ldy #$FF ; y = 0
  112. 000109 2
  113. 000109 2 clsloop:
  114. 000109 2 C8 iny ; y++
  115. 00010A 2 8A txa ; restore color
  116. 00010B 2
  117. 00010B 2 ; we'll do this call 4 times for each 255 byte (0x0100) sections
  118. 00010B 2 ; we could do it once for each section, but it's a lot slower.
  119. 00010B 2 ; we can do it 8 times for each section, but it doubles the code
  120. 00010B 2 ; chunk, so we'll just go with this for now. whatever.
  121. 00010B 2 99 00 40 sta RASTER + $0000, y
  122. 00010E 2 99 40 40 sta RASTER + $0040, y
  123. 000111 2 99 80 40 sta RASTER + $0080, y
  124. 000114 2 99 C0 40 sta RASTER + $00C0, y
  125. 000117 2
  126. 000117 2 99 00 41 sta RASTER + $0100, y
  127. 00011A 2 99 40 41 sta RASTER + $0140, y
  128. 00011D 2 99 80 41 sta RASTER + $0180, y
  129. 000120 2 99 C0 41 sta RASTER + $01C0, y
  130. 000123 2
  131. 000123 2 99 00 42 sta RASTER + $0200, y
  132. 000126 2 99 40 42 sta RASTER + $0240, y
  133. 000129 2 99 80 42 sta RASTER + $0280, y
  134. 00012C 2 99 C0 42 sta RASTER + $02C0, y
  135. 00012F 2
  136. 00012F 2 99 00 43 sta RASTER + $0300, y
  137. 000132 2 99 40 43 sta RASTER + $0340, y
  138. 000135 2 99 80 43 sta RASTER + $0380, y
  139. 000138 2 99 C0 43 sta RASTER + $03C0, y
  140. 00013B 2
  141. 00013B 2 ; use $FF for single, $7F for double, $3F for quad
  142. 00013B 2 C0 3F cpy #$3F ; does y==(last)?
  143. 00013D 2 D0 CA bne clsloop ; nope, go again
  144. 00013F 2
  145. 00013F 2 60 rts
  146. 000140 2
  147. 000140 2 .endif ; UseVideoDisplay0
  148. 000140 2 ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;
  149. 000140 2
  150. 000140 1
  151. 000140 1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  152. 000140 1 ;; RAM used
  153. 000140 1 KEYBAK = $10
  154. 000140 1 SHIFTSCRATCH = $11
  155. 000140 1
  156. 000140 1
  157. 000140 1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  158. 000140 1 ; main
  159. 000140 1 ; - the library entry point.
  160. 000140 1 main:
  161. 000140 1 .if .defined(UseVideoDisplay0)
  162. 000140 1 20 04 01 jsr cls ; clear the screen black
  163. 000143 1 .endif
  164. 000143 1 20 4F 01 jsr cls7seg
  165. 000146 1 20 5B 01 jsr displayVersion ; display the version number
  166. 000149 1 4C 6B 01 jmp keyinput ; press a key, get a color
  167. 00014C 1 20 03 01 jsr end ; end it
  168. 00014F 1
  169. 00014F 1
  170. 00014F 1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  171. 00014F 1 cls7seg:
  172. 00014F 1 ; 1. clear the 7 segment display
  173. 00014F 1 A9 00 lda #$00
  174. 000151 1 85 FB sta POINTH ; left two digits
  175. 000153 1 85 FA sta POINTL ; middle two digits
  176. 000155 1 85 F9 sta INH ; right two digits
  177. 000157 1 20 1F 1F jsr SCANDS ; draw it to the display
  178. 00015A 1 60 rts
  179. 00015B 1
  180. 00015B 1 displayVersion:
  181. 00015B 1 A9 00 lda #$00
  182. 00015D 1 85 F9 sta INH ; right two digits
  183. 00015F 1
  184. 00015F 1 A9 00 lda VERSIONH
  185. 000161 1 85 FB sta POINTH ; v00
  186. 000163 1 A9 01 lda VERSIONL
  187. 000165 1 85 FA sta POINTL ; 01
  188. 000167 1
  189. 000167 1 20 1F 1F jsr SCANDS ; draw it to the display
  190. 00016A 1 60 rts
  191. 00016B 1
  192. 00016B 1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  193. 00016B 1 keyinput:
  194. 00016B 1 ; check for key
  195. 00016B 1 20 6A 1F jsr GETKEY ; get a keypress
  196. 00016E 1 C9 15 cmp KEY_NONE ; $15 is "no press"
  197. 000170 1 F0 F9 beq keyinput ; then there's no press, check again
  198. 000172 1
  199. 000172 1 ; store aside a backup of the press
  200. 000172 1 85 10 sta KEYBAK ; KeyBak = a
  201. 000174 1
  202. 000174 1 ; check for AD/DA/PC/+ keys
  203. 000174 1 29 10 and KEY_SPECIAL_MASK
  204. 000176 1 C9 10 cmp KEY_SPECIAL_MASK
  205. 000178 1 D0 10 bne keyShiftIntoDisplay ; nope. regular key press
  206. 00017A 1
  207. 00017A 1 ; it's a control key!
  208. 00017A 1 handleControlKey:
  209. 00017A 1 A5 10 lda KEYBAK ; restore A
  210. 00017C 1 85 F9 sta INH ; just shove it to the display
  211. 00017E 1 A9 00 lda #$0 ; clear A
  212. 000180 1 85 FA sta POINTL ; short circuit
  213. 000182 1 85 FB sta POINTH
  214. 000184 1 20 1F 1F jsr SCANDS ; update display
  215. 000187 1 4C 6B 01 jmp keyinput ; repeat
  216. 00018A 1
  217. 00018A 1
  218. 00018A 1 ; handler for nibbles...
  219. 00018A 1 keyShiftIntoDisplay:
  220. 00018A 1 ; right byte
  221. 00018A 1 A5 10 lda KEYBAK ; A = Key pressed (A to be shifted in)
  222. 00018C 1
  223. 00018C 1 A6 F9 ldx INH ; X = INH
  224. 00018E 1 20 AC 01 jsr shifter ; shift around nibbles
  225. 000191 1 86 F9 stx INH ; store X back out
  226. 000193 1
  227. 000193 1 ; middle byte
  228. 000193 1 A6 FA ldx POINTL ; X from the byte
  229. 000195 1 20 AC 01 jsr shifter ; shift ecverything around
  230. 000198 1 86 FA stx POINTL ; store the modified X back out
  231. 00019A 1
  232. 00019A 1 ; left byte
  233. 00019A 1 A6 FB ldx POINTH ; X from the byte
  234. 00019C 1 20 AC 01 jsr shifter ; shift ecverything around
  235. 00019F 1 86 FB stx POINTH ; store the modified X back out
  236. 0001A1 1
  237. 0001A1 1 ; and finally display it to the screen
  238. 0001A1 1 20 1F 1F jsr SCANDS ; and display it to the screen
  239. 0001A4 1
  240. 0001A4 1
  241. 0001A4 1 .if .defined(UseVideoDisplay0)
  242. 0001A4 1 ; and display the color
  243. 0001A4 1 A5 10 lda KEYBAK
  244. 0001A6 1 20 06 01 jsr fillscr ; fill the screen
  245. 0001A9 1 .endif
  246. 0001A9 1
  247. 0001A9 1 4C 6B 01 jmp keyinput ; repeat...
  248. 0001AC 1
  249. 0001AC 1
  250. 0001AC 1 ; shifter
  251. 0001AC 1 ; roll A through X (for keypad->multibyte display use)
  252. 0001AC 1 ; eg: A=$0D X=$4C -> X=$CD A=$0C
  253. 0001AC 1 ; in: A - nibble to shift in from the right
  254. 0001AC 1 ; in: X - byte to work on
  255. 0001AC 1 ; mod: Y - scratch
  256. 0001AC 1 ; out: A - nibble shifted out
  257. 0001AC 1 shifter:
  258. 0001AC 1 ; 1. store aside A in Y
  259. 0001AC 1 29 0F and #$0F ; clean up A (just in case)
  260. 0001AE 1 85 11 sta SHIFTSCRATCH
  261. 0001B0 1 ; A = input byte / nib
  262. 0001B0 1 ; X = starting byte
  263. 0001B0 1 ; SHIFTSCRATCH = masked input nibble
  264. 0001B0 1
  265. 0001B0 1 ; 2. generate carry result, store on stack
  266. 0001B0 1 8A txa ; A = X
  267. 0001B1 1 4A lsr
  268. 0001B2 1 4A lsr
  269. 0001B3 1 4A lsr
  270. 0001B4 1 4A lsr ; A >>= 4 (shift nibble down)
  271. 0001B5 1 ;and #$0F ; A &= 0x0F (mask it) (unnecessary due to LSR)
  272. 0001B5 1 48 pha ; push A onto stack
  273. 0001B6 1
  274. 0001B6 1 ; A = carry nibble (junk now)
  275. 0001B6 1 ; X = starting byte
  276. 0001B6 1 ; SHIFTSCRATCH = masked input nibble
  277. 0001B6 1 ; stack = x >> 4 (carry nibble)
  278. 0001B6 1
  279. 0001B6 1 ; 3. shift nibble and apply new carry in
  280. 0001B6 1 8A txa ; A = X
  281. 0001B7 1 0A asl
  282. 0001B8 1 0A asl
  283. 0001B9 1 0A asl
  284. 0001BA 1 0A asl ; a <<=4 (shift nibble up)
  285. 0001BB 1 ;and #$F0 ; A &= 0xF0 (mask it) (unnecessary due to ASL)
  286. 0001BB 1 05 11 ora SHIFTSCRATCH ; A = A | SCRATCH ( shift in nibble)
  287. 0001BD 1 ; A = output byte (shifted nibbles)
  288. 0001BD 1 ; X = junk
  289. 0001BD 1 ; SHIFTSCRATCH = masked input nibble (junk now)
  290. 0001BD 1
  291. 0001BD 1 ; 4. Setup return values
  292. 0001BD 1 AA tax ; X = A
  293. 0001BE 1 68 pla ; pop A from stack (from 2.)
  294. 0001BF 1 ; X = output byte
  295. 0001BF 1 ; A = carry nibble
  296. 0001BF 1
  297. 0001BF 1 ; 5. and return
  298. 0001BF 1 60 rts ; return
  299. 0001BF 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement