Advertisement
brouhaha

assembly source code for MC6800 monitor for Apple 1

Jul 18th, 2011
1,030
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.15 KB | None | 0 0
  1. ; This is a rewrite of the Apple 1 monitor to run on an MC6800
  2. ; microprocessor, rather than the MCS6502 microprocessor that
  3. ; was standard. This source code will assemble with the
  4. ; AS Macro Assembler; with minor changes it should assemble
  5. ; with any MC6800 assembler.
  6.  
  7. ; Copyright 2011 Eric Smith <eric@brouhaha.com>
  8. ;
  9. ; This program is free software; you can redistribute and/or modify it
  10. ; under the terms of the GNU General Public License version 3 as
  11. ; published by the Free Software Foundation.
  12. ;
  13. ; This program is distributed in the hope that it will be useful, but
  14. ; WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. ; General Public License for more details.
  17. ;
  18. ; The text of the license may be found online at:
  19. ; http://www.brouhaha.com/~eric/software/GPLv3
  20. ; or:
  21. ; http://www.gnu.org/licenses/gpl-3.0.txt
  22.  
  23. cpu 6800
  24.  
  25. xam equ $0024 ; two bytes
  26. st equ $0026 ; two bytes
  27. h equ $0028
  28. l equ $0029
  29.  
  30. mode equ $002b
  31. ysav equ $002c ; two bytes
  32. inptr equ $002e ; two bytes
  33.  
  34. in equ $0200
  35.  
  36. kbd equ $d010
  37. kbd_cr equ $d011
  38. dsp equ $d012
  39. dsp_cr equ $d013
  40.  
  41. org $ff00
  42.  
  43. reset: ; cld ; No decimal mode on 6800, so we don't need
  44. ; need to clear it.
  45. ; cli ; Disable interrupts - not actually needed on reset.
  46. ldab #$7f ; Mask for DSP data direction register.
  47. stab dsp ; Set it up.
  48. ldab #$a7 ; KBD and DSP control register mask.
  49. stab kbd_cr ; Enable interrupts, set CA1, CB1, for
  50. stab dsp_cr ; positive edge sense/output mode.
  51. lds #$01ff ; On the 6502, the monitor didn't initialize the
  52. ; stack pointer, which was OK because it was
  53. ; guaranteed to be somewhere in page 1. Not so
  54. ; on the 6800!
  55. ; Ideally, I'd take advantage of the stack
  56. ; starting right before the input buffer to
  57. ; save a few bytes, but I haven't yet figured
  58. ; out how to do it.
  59.  
  60. ; Note that B contains $a7 here, which means that the incb below will
  61. ; set the negative flag, causing the bpl to fall through into escape.
  62. ; This saves us a "bra escape" instruction here.
  63.  
  64. ; Get a line of input from the keyboard, echoing to display.
  65. ; Normally enter at escape or getline.
  66.  
  67. notcr: cmpa #$df ; "_"? [NB back arrow]
  68. beq backspace ; Yes.
  69. cmpa #$9b ; ESC?
  70. beq escape ; Yes.
  71. inx ; Advance text index.
  72. incb
  73. bpl nextchar ; Auto ESC if > 127.
  74.  
  75. escape: ldaa #$dc ; "\".
  76. jsr echo ; Output it.
  77.  
  78. getline: ldaa #$8d ; CR.
  79. jsr echo ; Output it.
  80. ldx #in+1 ; Initiallize [sic] text index.
  81. ldab #1
  82. backspace: dex ; Back up text index.
  83. decb
  84. bmi getline ; Beyond start of line, reinitialize.
  85.  
  86. nextchar: ldaa kbd_cr ; Key ready?
  87. bpl nextchar ; Loop until ready.
  88. ldaa kbd ; Load character. B7 should be '1'.
  89. staa ,x ; Add to text buffer.
  90. bsr echo ; Display character.
  91. cmpa #$8d ; CR?
  92. bne notcr ; No.
  93.  
  94. ; Process an input line.
  95.  
  96. cr: ldx #in+256-1 ; Reset text index to in-1, +256 so that
  97. ; 'inc inptr+1' will result in $0200.
  98. stx inptr
  99. clra ; For XAM mode. 0->B.
  100.  
  101. setblok: asl a ; Leaves $56 if setting BLOCK XAM mode.
  102. setmode: staa mode ; $00 = XAM, $BA = STOR, $56 = BLOK XAM.
  103. blskip: inc inptr+1 ; Advance text index.
  104. nextitem: ldx inptr
  105. ldaa ,x ; Get character.
  106. cmpa #$8d ; CR?
  107. beq getline ; Yes, done this line.
  108. cmpa #$ae ; "."?
  109. beq setblok ; Set BLOCK XAM mode.
  110. bls blskip ; Skip delimiter.
  111. cmpa #$ba ; ":"?
  112. beq setmode ; Yes, set STOR mode.
  113. cmpa #$d2 ; "R"?
  114. beq run ; Yes, run user program.
  115. clr l ; $00->L.
  116. clr h ; and H.
  117. stx ysav ; Save Y for comparison.
  118.  
  119. nexthex: ldx inptr
  120. ldaa ,x ; Get character for hex test.
  121. eora #$b0 ; Map digits to $0-9.
  122. cmpa #$09 ; Digit?
  123. bls dig ; Yes.
  124. adda #$89 ; Map letter "A"-"F" to $FA-FF.
  125. cmpa #$f9 ; Hex letter?
  126. bls nothex ; No, character not hex.
  127.  
  128. dig: asla ; Hex digit to MSD of A.
  129. asla
  130. asla
  131. asla
  132.  
  133. ldab #$04 ; Shift count.
  134. hexshift: asla ; Hex digit left, MSB to carry.
  135. rol l ; Rotate into LSD.
  136. rol h ; Rotate into MSD's.
  137. decb ; Done 4 shifts?
  138. bne hexshift ; No, loop.
  139.  
  140. inc inptr+1 ; Advance text index.
  141. bra nexthex ; Always taken. Check next character for hex.
  142.  
  143. nothex: cpx ysav ; Check if L, H empty (no hex digits).
  144. beq escape ; Yes, generate ESC sequence.
  145. tst mode ; Test MODE byte.
  146. bpl notstor ; B6=0 for STOR, 1 for XAM and BLOCK XAM
  147.  
  148. ; STOR mode
  149. ldx st
  150. ldaa l ; LSD's of hex data.
  151. staa ,x ; Store at current 'store index'.
  152. inx
  153. stx st
  154. tonextitem: bra nextitem ; Get next command item.
  155.  
  156. prbyte: psh a ; Save A for LSD.
  157. lsra
  158. lsra
  159. lsra ; MSD to LSD position.
  160. lsra
  161. bsr prhex ; Output hex digit.
  162. pul a ; Restore A.
  163. prhex: anda #$0f ; Mask LSD for hex print.
  164. oraa #$b0 ; Add "0".
  165. cmpa #$b9 ; Digit?
  166. bls echo ; Yes, output it.
  167. adda #$07 ; Add offset for letter.
  168. echo: tst dsp ; DA bit (B7) cleared yet?
  169. bmi echo ; No, wait for display.
  170. staa dsp ; Output character. Sets DA.
  171. rts ; Return.
  172.  
  173. run: ldx xam
  174. jmp ,x ; Run at current XAM index.
  175.  
  176. notstor: bne xamnext ; mode = $00 for XAM, $56 for BLOCK XAM.
  177.  
  178. ldx h ; Copy hex data to
  179. stx st ; 'store index'.
  180. stx xam ; And to 'XAM index'.
  181. clra ; set Z flag to force following branch.
  182.  
  183. nxtprnt: bne prdata ; NE means no address to print.
  184. ldaa #$8d ; CR.
  185. bsr echo ; Output it.
  186. ldaa xam ; 'Examine index' high-order byte.
  187. bsr prbyte ; Output it in hex format.
  188. ldaa xam+1 ; Low-order 'Examine index' byte.
  189. bsr prbyte ; Output it in hex format.
  190. ldaa #$ba ; ":".
  191. bsr echo ; Output it.
  192.  
  193. prdata: ldaa #$a0 ; Blank.
  194. bsr echo ; Output it.
  195.  
  196. ldx xam
  197. ldaa ,x ; Get data byte at 'examine index'.
  198. bsr prbyte ; Output it in hex format.
  199.  
  200. xamnext: clr mode ; 0->MODE (XAM mode).
  201. ldx xam ; Compare 'examine index' to hex data.
  202. cpx h
  203. beq tonextitem ; Not less, so more data to output.
  204. inx
  205. stx xam
  206. ldaa xam+1 ; Check low-order 'examine index' byte
  207. anda #$07 ; For MOD 8 = 0
  208. bra nxtprnt ; always taken
  209.  
  210. org $fff8 ; vector table
  211. fdb $0000 ; IRQ
  212. fdb $0000 ; SWI
  213. fdb $f000 ; NMI
  214. fdb $ff00 ; RESET
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement