home *** CD-ROM | disk | FTP | other *** search
/ Transactor / Transactor_15_1987_Transactor_Publishing.d64 / ramcart.merlin < prev    next >
Text File  |  2023-02-26  |  4KB  |  161 lines

  1. org $8000
  2.  
  3. ***  equates ***
  4.  
  5. txttab  = $2b      ;start of basic text
  6. vartab  = $2d      ;end of basic text
  7. source  = $5f      ;start of source to copy
  8. end     = $5a      ;end+1 of source to copy
  9. dest    = $58      ;end+1 of destination
  10. ndx     = $c6      ;no of characters in keyboard buffer
  11. keyd    = $0277    ;start of keyboard buffer
  12. warm    = $0302    ;basic warm start vector
  13. copy    = $a3bf    ;copy memory
  14. strout  = $ab1e    ;print string
  15. vicctrl = $d016    ;vic control register
  16. vectors = $e453    ;copy basic vectors to ram
  17. init    = $e3bf    ; initialize basic interpreter
  18. ioinit  = $fda3    ;initialize i/o
  19. ramtas  = $fd50    ;initialize memory pointers
  20. restor  = $fd15    ;restore i/o vectors
  21. cint    = $ff5b    ;init screen and keyboard
  22. nmicont = $fe5e    ;continue with nmi routine
  23.  
  24.  
  25. *** auto-start basic program ***
  26.  
  27.  
  28. ;place start of code in cartridge vectors
  29. dfb <start,>start
  30. dfb <nmicont,>nmicont
  31. ;'cbm' with bit 7 set
  32. dfb $c3,$c2,$cd
  33. ;'80'
  34. dfb $38,$30
  35.  
  36. ;'start' calls most of the routines
  37. ;which would be executed if a cartridge
  38. ;had not been detected.  system vectors
  39. ;and basic are initialized.
  40.  
  41. start  ldx #$05
  42. stx vicctrl
  43. jsr ioinit
  44. jsr ramtas
  45. jsr restor
  46. jsr cint
  47. cli
  48. jsr vectors
  49. jsr init
  50. ldx #$fb
  51. txs         ;initialize stack pointer
  52.  
  53.  
  54. ;copy the basic program from
  55. ;the area under $a000 to the start-of-basic
  56. ;and set up the basic text and variables
  57. ;vectors.  place 'run' in the keyboard buffer and
  58. ;enter basic through the warm start vector.
  59.  
  60. ldy txtt    ;store start of basic
  61. ldx txtt+1  ;saved with program
  62. sty txttab  ;at op system vector
  63. stx txttab+1
  64. ldy stsour  ;store start of source
  65. ldx stsour+1;at vector for copy routine
  66. sty source
  67. stx source+1
  68. ldy vart    ;store end of destination (+1)
  69. ldx vart+1  ;at copy routine vector
  70. sty dest
  71. stx dest+1
  72. dey         ;subtract one from low byte
  73. cpy #$ff
  74. bne cont
  75. dex         ;subtract borrow
  76. cont   sty vartab  ;store op system vector
  77. stx vartab+1
  78. lda #$a0    ;end of source (+1) = $a000
  79. sta end+1
  80. lda #$00
  81. sta end
  82. jsr copy
  83. lda #'r'
  84. sta keyd
  85. lda #'u'
  86. sta keyd+1
  87. lda #'n'
  88. sta keyd+2
  89. lda #$0d    ;<return>
  90. sta keyd+3
  91. lda #$04    ;number of characters
  92. sta ndx
  93. jmp (warm)
  94.  
  95.  
  96. *** store basic program to cartridge ***
  97. ;calculate the size of the basic text, and
  98. ;print an error message if too large to fit
  99. ;in the cartridge.  if okay, subtract the size
  100. ;from $9fff to get the location of the start
  101. ;of the copy to be saved to cartridge.  save
  102. ;that vector, and the start and end of basic
  103. ;text for future use.  set-up vectors for
  104. ;copy routine and copy program to cartridge.
  105.  
  106. store  sec
  107. lda vartab+1
  108. sbc txttab+1;find size of basic program
  109. tax
  110. lda vartab
  111. sbc txttab
  112. tay
  113. cpx #$1f    ;max size allowed
  114. bcs error   ;print error message and quit
  115. sty stsour  ;store size temporarily
  116. stx stsour+1
  117. sec
  118. lda #$9f    ;subtract size from $9fff to find
  119. sbc stsour+1;start of program in cartridge memory
  120. sta stsour+1
  121. lda #$ff
  122. sbc stsour
  123. sta stsour
  124. lda txttab  ;store start of basic for cartridge
  125. sta txtt    ;use and in vector for copy routine
  126. sta source
  127. lda txttab+1
  128. sta txtt+1
  129. sta source+1
  130. ldy vartab  ;store end of basic (+1) for cartridge
  131. ldx vartab+1;use and vector for copy routine
  132. iny
  133. bne cont1
  134. inx
  135. cont1  sty vart
  136. sty end
  137. stx vart+1
  138. stx end+1
  139. lda #$a0    ;store $a000 (end of cartridge memory +1)
  140. sta dest++1 ;in vector for copy routine
  141. lda #$00
  142. sta dest
  143. jsr copy
  144. rts
  145.  
  146.  
  147. *** print error message ***
  148.  
  149. error  lda #<message
  150. ldy #>message
  151. jsr strout
  152. rts
  153.  
  154. message asc "PROGRAM TOO LARGE",0a,0d,00
  155.  
  156. *** system vector storage ***
  157.  
  158. txtt   dfb $00,$00 ;start of program in ram
  159. vart   dfb $00,$00 ;end of program in ram
  160. stsour dfb $00,$00 ;start of source in cartridge
  161.