1
0

dbug12.asm 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. ;; D-BUG12 Emulator
  2. ;; Copyright (c) 1998, Thomas Almy. All rights reserved.
  3. ;; Revised October 1999.
  4. ;; License is granted users of his 68HC12 Simulator
  5. ;; to use this file as part of their own programs for
  6. ;; educational or personal (but not commercial) use. This
  7. ;; file may not be given or sold to anyone without permission
  8. ;; of the author.
  9. ;; Thomas Almy makes no representation about the suitability
  10. ;; of this software for any purpose. It is provided as is without
  11. ;; warranty of any kind, expressed or implied.
  12. ;; ***How to use the D-BUG12 Emulator***
  13. ; The D-BUG12 Emulator is a minimal implementation which has the following
  14. ; functionality:
  15. ; 1. Handles the reset vector.
  16. ; 2. Implements SetUserVector, GetChar, Putchar (if you want more, feel free
  17. ; to add the functionality and send your extension back to me for
  18. ; incorporation in future versions of this file).
  19. ; 3. Allows SWI to end program execution
  20. ; 4. Disables COP timer, set stack pointer, initializes SCI 0 to 9600bps,
  21. ; sets clock stretch, and clears X bit as part of initialization.
  22. ;
  23. ; Naturally a full D-BUG12 emulation is not necessary, because the 68HC12
  24. ; simulator has the capabilities of the D-BUG12 user interface.
  25. ;
  26. ; To use this routine, first assemble it. Then:
  27. ; 1. From the Simulator, load DBUG12.S19.
  28. ; 2. Load your program.
  29. ; 3. Do a reset, then "go". Execution will stop at a BGND instruction.
  30. ; 4. Set the PC to the start of your program, if not at $4000.
  31. ; 5. Use "go" or "trace" normally.
  32. ; 6. If execution stops with a D-BUG12 BGND instruction with the next
  33. ; instruction displayed being a "BRA", register X contains the vector
  34. ; number of the interrupt that occured (i.e., 27 ($1b) would be an SWI
  35. ; instruction.)
  36. ; 7. If execution stops with a D-BUG12 BGND instruction where the next
  37. ; instruction displayed being a "RTS", this is an un-implemented D-BUG12
  38. ; routine. Feel free to write it for extra credit.
  39. #include EQUATES.ASM
  40. ORG $A00 ; RAM interrupt table
  41. table ds 58
  42. tabend equ *
  43. ;; Routine Vector table
  44. ORG $FE00
  45. dw die
  46. dw getchar
  47. dw putchar
  48. dw die
  49. dw die
  50. dw die
  51. dw die
  52. dw die
  53. dw die
  54. dw die
  55. dw die
  56. dw die
  57. dw die
  58. dw setuv ; $fe1a
  59. dw die
  60. dw die
  61. dw die
  62. dw die
  63. ORG $FFCE ; Vector table
  64. dw keyhint ; ffce
  65. dw keyjint ; ffd0
  66. dw atdint ; ffd2
  67. dw sci1int ; ffd4
  68. dw sci0int ; ffd6
  69. dw spiint ; ffd8
  70. dw paieint ; ffda
  71. dw paoint ; ffdc
  72. dw tovint ; ffde
  73. dw tc7int ; ffe0
  74. dw tc6int ; ffe2
  75. dw tc5int ; ffe4
  76. dw tc4int ; ffe6
  77. dw tc3int ; ffe8
  78. dw tc2int ; ffea
  79. dw tc1int ; ffec
  80. dw tc0int ; ffee
  81. dw rtiint ; fff0
  82. dw irqint ; fff2
  83. dw xirqint ; fff4
  84. dw swiint ; fff6
  85. dw trapint ; fff8
  86. dw coprst ; fffa
  87. dw clkrst ; fffc
  88. dw rstrst ; fffe
  89. ORG $F000 ; Start of "ROM"
  90. die: bgnd ; We can't handle call
  91. rts ; so stop then return
  92. clkrst:
  93. coprst:
  94. rstrst: ; On reset, clear the user table,
  95. ; set the stack pointer, clear the X flag
  96. ; turn off clock timer, set the ECLK delays
  97. ; and return to the monitor
  98. ldx #table
  99. l1: clr 1,X+
  100. cpx #tabend
  101. bne l1
  102. clr COPCTL
  103. movb #$35 CSSTR0
  104. movb #$ff CSSTR1
  105. andcc #$bf
  106. movw #52 SC0BDH
  107. movb #$0c SC0CR2
  108. lds #$a00
  109. l2: bgnd ; Stop, then proceed to $4000
  110. jmp PRSTART
  111. swiint: ldx #UserSWI*2
  112. bra handler
  113. trapint: ldx #UserTrap*2
  114. bra handler
  115. xirqint: ldx #UserXIRQ*2
  116. bra handler
  117. irqint: ldx #UserIRQ*2
  118. bra handler
  119. rtiint: ldx #UserRTI*2
  120. bra handler
  121. tovint: ldx #UserTimerOvf*2
  122. bra handler
  123. paieint: ldx #UserPAccEdge*2
  124. bra handler
  125. paoint: ldx #UserPAccOvf*2
  126. bra handler
  127. tc0int: ldx #UserTimerCh0*2
  128. bra handler
  129. tc1int: ldx #UserTimerCh1*2
  130. bra handler
  131. tc2int: ldx #UserTimerCh2*2
  132. bra handler
  133. tc3int: ldx #UserTimerCh3*2
  134. bra handler
  135. tc4int: ldx #UserTimerCh4*2
  136. bra handler
  137. tc5int: ldx #UserTimerCh5*2
  138. bra handler
  139. tc6int: ldx #UserTimerCh6*2
  140. bra handler
  141. tc7int: ldx #UserTimerCh7*2
  142. bra handler
  143. spiint: ldx #UserSPI0*2
  144. bra handler
  145. sci0int: ldx #UserSCI0*2
  146. bra handler
  147. sci1int: ldx #UserSCI1*2
  148. bra handler
  149. atdint: ldx #UserAtoD*2
  150. bra handler
  151. keyjint: ldx #UserPortJKWU*2
  152. bra handler
  153. keyhint: ldx #UserPortHKWU*2
  154. handler: ldy table,X ; See if there is a vector
  155. beq noHandler
  156. jmp 0,Y
  157. noHandler:
  158. xgdx
  159. lsrd
  160. xgdx
  161. bgnd ; Stop because no handler
  162. ; X has table index
  163. bra noHandler
  164. getchar:
  165. brclr SC0SR1 #$20 getchar ; wait for character available
  166. ldab SC0DRL
  167. rts
  168. putchar:
  169. brclr SC0SR1 #$80 putchar ; wait until buffer clear
  170. stab SC0DRL
  171. rts
  172. setuv: cpd #-1 ; Check value
  173. bne setvec ; set vector if not -1
  174. ldd #table ; else return table address
  175. rts
  176. outOfRange:
  177. ldd #-1 ; invalid request
  178. rts
  179. setvec: cpd #UserPortHKWU
  180. blt outOfRange
  181. cpd #UserTrap
  182. bgt outOfRange
  183. asld
  184. addd #table
  185. tfr D X ; put offset into x
  186. movw 2,SP 0,X ; set value
  187. ldd #0
  188. rts