home *** CD-ROM | disk | FTP | other *** search
/ 8bitfiles.net/archives / archives.tar / archives / commodore-scene-files / Coverdisks / CDU / V4D02.D64 / loadv2.4.asm < prev    next >
Encoding:
Assembly Source File  |  2019-04-13  |  10.9 KB  |  606 lines

  1. e
  2. _*********************************************************
  3. _*                                                       *
  4. _*       module name : LOAD.ASM                          *
  5. _*                                                       *
  6. _*                Maintenance log                        *
  7. _*                ---------------                        *
  8. _*                                                       *
  9. _*   date      time                     action           *
  10. _*   ----      ----                     ------           *
  11. _* 25/02/89    02:00                 initial coding      *
  12. _* 29/03/89    19:20                 tidy up and fix     *
  13. _* 03/04/89    22:00               further tidy up       *
  14. _* 03/04/89    23:00      change brackets, fix ass bugs  *
  15. _* 05/04/89    19:00         fixed the patchend bug      *
  16. _* 06/04/89    23:30  move zero defns and fix init bug   *
  17. _* 25/04/89    22:30  fix bugs, added $ff05-$ffff copy   *
  18. _* 29/04/89     9:55  updated patch table + other mods   *
  19. _* 05/05/89    17:50     fixed the page area bugs        *
  20. _* 22/05/89    18:05  updated for new options on locstor *
  21. _* 18/06/89    19:00  System registers placed on stack   *
  22. _* 25/06/89    18:10  Save the stack pointer missing     *
  23. _* 04/07/89    18:50  page 0 and 1 can be in any ram     *
  24. _*********************************************************
  25.  
  26.  
  27. _*********************************************************
  28. _*                                                       *
  29. _*       routine : INITLOAD - initialise the loader      *
  30. _*                 by copying it then patching it        *
  31. _*                                                       *
  32. _*   entry                                               *
  33. _*   -----                                               *
  34. _*   none                                                *
  35. _*.......................................................*
  36. _*   used                                                *
  37. _*   ----                                                *
  38. _*   A,X,Y                                               *
  39. _*.......................................................*
  40. _*   exit                                                *
  41. _*   ----                                                *
  42. _*   none                                                *
  43. _*********************************************************
  44.  
  45.  
  46.  
  47.  
  48. _ equates used                                         
  49.  
  50. copystrt    = $e000
  51. ram0conf    = $3f
  52. filenum    = 1
  53. device    = 8
  54. secondad    = 1
  55. defpri    = 128
  56. loadprg    = $f265
  57. errload    = $f5b5
  58.  
  59.  
  60. _ other required storage
  61.  
  62. pritext    res 3
  63. savecnt    res 1
  64. stktemp    res 1            _ area to save stack pointer
  65.  
  66. _
  67. _   Start of the code
  68. _
  69.  
  70. initload    equ *
  71.     ¥ #zeroadd
  72.     » ldaset        _ for LDAFAR
  73.     » staset        _ for STAFAR
  74.     ¥ #>copystrt
  75.     » zeroadd
  76.     ¥ #<copystrt
  77.     » zeroadd+1
  78.     ƒ #0
  79.  
  80. _
  81. _ copy the code from $e000 to $feff
  82. _ Note that as this could run in BANK 15, ie with system ROMs
  83. _ enabled, you can LDA from kernal ROM and STA into RAM without
  84. _ having to change configurations. When you try to write to ROM
  85. _ it actually writes to the RAM underneath.
  86. _
  87.  
  88.  
  89. initlod1    equ *
  90.     ₧ #$00
  91.     £ ldafar
  92.     ₧ #ram0conf
  93.     £ stafar
  94.     ÿ zeroadd
  95.     ê initlod1
  96.     ÿ zeroadd+1
  97.     ¥ zeroadd+1
  98.     æ #$ff
  99.     ê initlod1
  100.  
  101. _
  102. _ copy the code from $ff05 - $ffff
  103. _
  104.     ƒ #5
  105. initlod9    equ *
  106.     ₧ #0
  107.     £ ldafar
  108.     ₧ #ram0conf
  109.     £ stafar
  110.     Ü
  111.     ê initlod9
  112.  
  113.  
  114. _ code copied, now patch it.
  115.  
  116.     ₧ #0
  117.     ƒ #0
  118. patchlop    equ *
  119.     ¥ patchtab,x
  120.     » zeroadd
  121.     ¥ patchtab+1,x
  122.     » zeroadd+1
  123.     ¥ patchtab+2,x
  124.     ░ savecnt
  125.     ₧ #ram0conf
  126.     £ stafar
  127.     ₧ savecnt
  128.     Ö
  129.     Ö
  130.     Ö
  131.     Æ #patchend
  132.     â patchlop
  133.  
  134. _ code now patched so return to caller
  135.  
  136.     ¬
  137.  
  138. patchtab    equ *
  139.     db  $73,$e5,$ea        _ remove SEI
  140.     db  $ee,$f3,$ea        _ remove SEI
  141.     db  $ba,$e5,$ea        _ remove CLI
  142.     db  $8f,$f4,$ea        _ remove CLI
  143.     db  $54,$f4,$2c        _ remove test for run/stop
  144.     db  $57,$f4,$4c        _ jmp over check for run/stop flag
  145.     db  $58,$f4,$5c
  146.     db  $59,$f4,$f4
  147.     db  $d5,$f2,$4c        _ jmp over check for run/stop flag
  148.     db  $d6,$f2,$da
  149.     db  $d7,$f2,$f2
  150.     db  $21,$f4,$4c        _ point to new code
  151.     db  $22,$f4
  152.     db  >burstmod
  153.     db  $23,$f4
  154.     db  <burstmod
  155.     db  $b0,$f2,$4c        _ point to new code
  156.     db  $b1,$f2
  157.     db  >loadmod
  158.     db  $b2,$f2
  159.     db  <loadmod        
  160.     db  $51,$f4,$f8        _ file read to 248
  161.  
  162. patchend  equ * - patchtab
  163.  
  164.  
  165. _*********************************************************
  166. _*                                                       *
  167. _*       routine : LOAD - the load routine.              *     
  168. _*    cmd format : L progname,pri                        *
  169. _*                                                       *
  170. _*   entry                                               *
  171. _*   -----                                               *
  172. _*   CHARBUFF - command line input                       *
  173. _*   Y        - position in the command buffer           *
  174. _*.......................................................*
  175. _*   used                                                *
  176. _*   ----                                                *
  177. _*   A,X,Y                                               *
  178. _*.......................................................*
  179. _*   exit                                                *
  180. _*   ----                                                *
  181. _*   none                                                *
  182. _*********************************************************
  183.  
  184.  
  185. load    equ *
  186.     ¥ #prgnorun
  187.     db  $2c
  188. execute    equ *
  189.     ¥ #prgrun
  190.     » option
  191.     £ readload          _ read information into prgname and get pri
  192.     â nosyntax
  193.     ¬
  194.     
  195.  
  196. _ Ok, we are ready to load, We now call the patched code for the loader. First
  197. _ by switching the bank to RAM, then calling the routine. This method 
  198. _ saves the problem of having to code a full loader with serial routines
  199. _ which would have to be done for a full operating system.           
  200.  
  201. nosyntax    equ *
  202.     £ locfree        _ locate a free entry in the table
  203.     â allok
  204.     ¥ #6
  205.     ¢ dispmess
  206.  
  207. allok    equ *
  208.     ¥ #$3e        _ RAM block 0, but all I/O available 
  209.     » confreg
  210.  
  211. _ setup for the load routine
  212.  
  213.     ¥ #filenum
  214.     » lfn        _ LFN
  215.     ¥ #device        _ serial device
  216.     » dev
  217.     ¥ #secondad        _ SA
  218.     » sa    
  219.     ¥ namelen
  220.     » prgnlen
  221.     ¥ #>prgname
  222.     » prgnadd
  223.     ¥ #<prgname
  224.     » prgnadd+1
  225.     ¥ #0        _ bank number 0, not configuration no.
  226.     » namebank        _ bank where name is found.
  227.     ¥ #$00
  228.     » iomode        _ stop all output from system
  229.  
  230.     ¥ #11
  231.     £ dispmess    
  232.     £ loadprg        _ calls code within this subroutine block    
  233.     â noloderr
  234.     ¥ #9
  235.     ¢ dispmess
  236.  
  237. _ program now in memory, so relocate, then setup table entry
  238. _ note the end address is in X,Y and the load routine has already
  239. _ set up some parameters for the relocation.
  240.  
  241. noloderr    equ *
  242.     ░ newend
  243.     ▒ newend+1            _ save prog end address
  244.  
  245.     ¥ #12
  246.     £ dispmess
  247.     £ reloc        _ newexec passed back ny this routine
  248.                 _ and newend not altered
  249.  
  250. _ table entry setup
  251.  
  252.     ƒ #flag
  253.     ¥ option
  254.     » [tabpntr],y        _ set mode of program
  255.  
  256. _ put name into the table
  257.  
  258.     ₧ #0                        
  259.     ƒ #name
  260. loadlop2    equ *
  261.     ¥ prgname,x
  262.     » [tabpntr],y
  263.     Ü
  264.     Ö
  265.     Æ namelen
  266.     â loadlop2
  267.     ¥ #space
  268. loadlop8    equ *
  269.     » [tabpntr],y
  270.     Ö
  271.     Ü
  272.     Æ #maxlen
  273.     â loadlop8        
  274.  
  275. _ save ram, start and end addresses
  276.  
  277.     ¥ ramused
  278.     ƒ #ramprg
  279.     » [tabpntr],y
  280.     ¥ startram
  281.     ƒ #strtadd
  282.     » [tabpntr],y
  283.     Ü
  284.     ¥ startram+1
  285.     » [tabpntr],y
  286.     ƒ #endadd
  287.     ¥ newend            _ relying on reloc not changing them
  288.     » [tabpntr],y
  289.     Ü
  290.     ¥ newend+1
  291.     » [tabpntr],y
  292.  
  293. _ set the priority value now
  294.  
  295.     ¥ pritemp
  296.     ƒ #priority
  297.     » [tabpntr],y
  298.  
  299. _ save the zero and page one locations
  300. _ and put page 1 of new program available
  301.  
  302.     ƒ #zerooff
  303.     ¥ zeropage
  304.     » [tabpntr],y
  305.     ƒ #ramprg
  306.     ¥ [tabpntr],y
  307.     » page1hi
  308.     ƒ #oneoff
  309.     ¥ pageone
  310.     » [tabpntr],y
  311.     » page1low
  312.  
  313.  
  314. _ set up the register info. This could be passed by the user or
  315. _ as an expansion allow file setup to define the information
  316. _ first though, the stack needs to be preserved...
  317.  
  318.     ┤
  319.     ░ stktemp
  320.  
  321.     ₧ #$ff
  322.     ╢
  323.     ¥ newexec+1
  324.     ú
  325.     ¥ newexec
  326.     ú
  327.     ¥ #0
  328.     ú                _ status register
  329.     ú                _ A
  330.     ú                _ X
  331.     ú                _ Y
  332.     ƒ #ramprg
  333.     ¥ [tabpntr],y
  334.     £ convram
  335.     ú
  336.  
  337. _ Save the new stack in the table ready to simulate a return of interrupt
  338.  
  339.     ƒ #regsp
  340.     ┤
  341.     ╡
  342.     » [tabpntr],y
  343.  
  344. _ restore the old page 1
  345.  
  346.     ¥ #osp1hi
  347.     » page1hi
  348.     ¥ #osp1low
  349.     » page1low
  350.     ₧ stktemp
  351.     ╢
  352.  
  353.     ¥ option
  354.     æ #prgnorun
  355.     ê tryrun
  356.     ¬
  357. tryrun    equ *
  358.     ¢ loadrun
  359.  
  360. _ read name and priority, convert priority and store in the table
  361.  
  362. readload    equ *
  363.     ₧ #0
  364. namelop1    equ *
  365.     Ü
  366.     ¥ charbuff,y        _ Y points to next char
  367.     æ #space
  368.     à namelop1
  369.     æ #comma
  370.     à getpri
  371.     æ #cr
  372.     ê onpri
  373.     ░ namelen
  374.     ¥ #defpri            _ default priority
  375.     » pritemp
  376.     ì
  377.     ¬
  378. onpri    equ *
  379.     » prgname,x
  380.     Ö
  381.     Æ #16
  382.     â namelop1
  383.     ¥ #7
  384.     £ dispmess
  385.     ¼
  386.     ¬
  387.  
  388.  
  389. getpri    equ *
  390.     ░ namelen
  391.     ₧ #0
  392. namelop2    equ *
  393.     Ü
  394.     ¥ charbuff,y
  395.     æ #cr
  396.     à transfer
  397.     » pritext,x
  398.     Ö
  399.     Æ #4
  400.     â namelop2
  401.     ¢ prierr
  402.  
  403. _ convert priority now
  404.  
  405. transfer    equ *
  406.     ╡
  407.     ₧ #0
  408.     ░ pritemp
  409.     æ #2
  410.     â ones
  411.     æ #3
  412.     â tens
  413.     ¥ pritext
  414.     £ conv
  415.     æ #3
  416.     ä prierr
  417.     £ mult10
  418.     £ mult10
  419.     » pritemp
  420.     Ö
  421. tens    equ *
  422.     ¥ pritext,x
  423.     £ conv
  424.     £ mult10
  425.     ì
  426.     Ç pritemp
  427.     » pritemp
  428.     Ö
  429. ones    equ *
  430.     ¥ pritext,x
  431.     £ conv
  432.     ì
  433.     Ç pritemp
  434.     » pritemp
  435.     ì
  436.     ¬
  437. prierr    equ *
  438.     ¥ #8
  439.     £ dispmess
  440.     ¼
  441.     ¬
  442.  
  443. _ above logic could not cope with 273 or 259 for example.
  444.  
  445.  
  446.  
  447. _ Now locate the memory required. (check the end address in save and
  448. _ get the correct method for calculation of length required)
  449.  
  450. _
  451. _ The following code is a modification to the load routine to load in
  452. _ extra information and then set up the relocation information
  453. _ the final part for relocation setup is completed when load is done.
  454. _
  455.  
  456.  
  457. loadmod    equ *
  458.     £ $e43e
  459.     » oldadd
  460.     £ $e43e
  461.     » oldadd+1            _ set up for relocation
  462.     £ $e43e
  463.     » oldend
  464.     £ $e43e
  465.     » oldend+1
  466.     £ $e43e
  467.     » execadd
  468.     £ $e43e
  469.     » execadd+1
  470.     £ procdata
  471.     ä loderror
  472.     ¢ $f2ba
  473.  
  474. burstmod    equ *
  475.     £ $f503
  476.     £ $f4ba
  477.     » oldadd
  478.     £ $f503
  479.     £ $f4ba
  480.     » oldadd+1
  481.     £ $f503
  482.     £ $f4ba
  483.     » oldend
  484.     £ $f503
  485.     £ $f4ba
  486.     » oldend+1
  487.     £ $f503
  488.     £ $f4ba
  489.     » execadd
  490.     £ $f503
  491.     £ $f4ba
  492.     » execadd+1
  493.     Ñ
  494.     ú
  495.     æ #$1f
  496.     ê notlast
  497.     ¥ $a5
  498.     ¼
  499.     ½ #4
  500.     » $a5
  501. notlast    equ *
  502.     £ procdata
  503.     ä loderror
  504.     ¢ $f434
  505. loderror    equ *
  506.     ¬            _ return to the calling loader with c=1
  507.  
  508.  
  509. _
  510. _ Note that end - start will give the correct length as the end is one
  511. _ more than it should be.
  512. _
  513.  
  514. procdata    equ *
  515.     ¥ oldend
  516.     ¼
  517.     ½ oldadd
  518.     » givelen
  519.     ¥ oldend+1
  520.     ½ oldadd+1
  521.     » givelen+1
  522.     ¥ #nostopt        _ no options required
  523.     £ locstor        _ storage located for program.
  524.     ä exitload
  525.  
  526. _ Storage located ok, so set up the correct load information
  527. _ ie new start address and bank to load into
  528.  
  529.     ¥ startram
  530.     » startlo            _ setup for load
  531.     » newstart            _ setup for the relocation
  532.     ¥ startram+1
  533.     » starthi
  534.     » newstart+1
  535.     ¥ ramused
  536.     £ convram
  537.     » prglodbk
  538.     » newram
  539.  
  540. _
  541. _ find areas for page 0 and page 1. Done here because if you can't locate
  542. _ the storage, there isn't any point continuing the load.
  543. _
  544.  
  545.     ¥ #0
  546.     » givelen
  547.     ¥ #1        _ 1 page required.
  548.     » givelen+1
  549.     ¥ #pagbound        _ just locate any old page
  550.     £ locstor        _ to store the ram of the pages.
  551.     ä exitload
  552.     ¥ startram+1
  553.     » zeropage
  554.     ¥ ramused    
  555.     » zeroram
  556.     ¥ #0
  557.     » givelen
  558.     ¥ #1        _ 1 page required.
  559.     » givelen+1
  560.     ¥ #pagbound
  561.     £ locstor    
  562.     ä exitload
  563.     ¥ startram+1
  564.     » pageone    
  565.     ¥ ramused
  566.     » oneram
  567.     ¬
  568.  
  569. exitload  equ *
  570.  
  571. _
  572. _ Close all the files etc., this routine will set the carry flag
  573. _ and issue a return which will then return to the caller.
  574. _
  575.  
  576.     ¢ errload
  577.  
  578. _
  579. _ convert a character to a value
  580. _
  581.  
  582. conv    equ *
  583.     ¼
  584.     ½ #50
  585.     ¬
  586.  
  587. _
  588. _ multiply A by 10 and return the value in A
  589. _
  590.  
  591. Mult10    equ *
  592.     é
  593.     » temp
  594.     é 
  595.     é 
  596.     é 
  597.     ì
  598.     Ç temp
  599.     ¬
  600.  
  601.     IEND
  602.  
  603.  
  604.  
  605.  
  606.