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

  1. e
  2. _*********************************************************
  3. _*                                                       *
  4. _*       module name : RELOC.ASM                         *
  5. _*                                                       *
  6. _*                Maintenance log                        *
  7. _*                ---------------                        *
  8. _*                                                       *
  9. _*   date      time                     action           *
  10. _*   ----      ----                     ------           *
  11. _* 24/02/89    01:00                 initial coding      *
  12. _* 28/03/89    22:45      fix bugs, update logic, tidy   *
  13. _* 03/04/89    23:50      added oldend, fixed ass bugs   *
  14. _* 06/04/89    23:20      moved zero page definitions    *
  15. _* 03/05/89    17:40        fix DEY bug                  *
  16. _* 31/09/89    16:00      fix getlen bug & end check bug *
  17. _*********************************************************
  18.  
  19.  
  20.  
  21. _*********************************************************
  22. _*                                                       *
  23. _*       routine : RELOC                                 *
  24. _*                                                       *
  25. _*   entry                                               *
  26. _*   -----                                               *
  27. _*   OLDADD   - Old start address of program             *  
  28. _*   OLDEND   - old end address of program               *
  29. _*   NEWSTART - new start address of program             *  
  30. _*   NEWEND   - new end address of program               *
  31. _*   NEWRAM   - configuration of new program to relocate *
  32. _*   EXECADD  - old execute address                      *
  33. _*.......................................................*
  34. _*   used                                                *
  35. _*   ----                                                *
  36. _*   A,Y                                                 *
  37. _*.......................................................*
  38. _*   exit                                                *
  39. _*   ----                                                *
  40. _*   NEWEXEC  - new execute address                      *
  41. _*   NEWEND   - new end address of the program           *
  42. _*              never updated and used outside           *
  43. _*********************************************************
  44.  
  45.  
  46. _ start of the code
  47. _ calculate the actual program start address and sets the 
  48. _ relocate pointer to start from that point.
  49.  
  50. reloc    equ *
  51.     ¥ execadd
  52.     ¼
  53.     ½ oldadd        
  54.     » newexec
  55.     ¥ execadd+1
  56.     ½ oldadd+1
  57.     » newexec+1
  58.     ¥ newexec
  59.     ì
  60.     Ç newstart
  61.     » newexec
  62.     » progptr
  63.     ¥ newexec+1
  64.     Ç newstart+1
  65.     » newexec+1
  66.     » progptr+1
  67.  
  68. _ setup LDAFAR and STAFAR with progptr as zero page address
  69.        
  70.     ¥ #progptr
  71.     » ldaset
  72.     » staset
  73.  
  74. relloop1    equ *
  75.     ƒ #0
  76.     ₧ newram        _ get ram block of program
  77.     £ ldafar        _ get machine code command
  78.     £ getlen        _ get length of command
  79.     æ #3        _ if 3 then command has an address
  80.     à addrcmd
  81.     ¢ moveon
  82.  
  83.  
  84. _ 3 byte command so get the address following
  85.  
  86. addrcmd    equ *
  87.     Ü
  88.     £ ldafar
  89.     » curradd
  90.     Ü
  91.     £ ldafar
  92.     » curradd+1
  93.     
  94. _ address got, so see if it is in range of the start and end addresses
  95.  
  96.     £ checklim       _ doesn't affect Y register
  97.     â moveon3
  98.     
  99. _ calculate newadd = curradd - oldadd + newstart
  100.  
  101.     ¥ curradd 
  102.     ¼
  103.     ½ oldadd
  104.     » curradd
  105.     ¥ curradd+1
  106.     ½ oldadd+1
  107.     » curradd+1
  108.     ¥ curradd
  109.     ì
  110.     Ç newstart
  111.     » curradd
  112.     ¥ curradd+1
  113.     Ç newstart+1
  114.     £ stafar        _ save curradd+1 in the program being rel'ed
  115.     û
  116.     ¥ curradd
  117.     £ stafar
  118. moveon3    equ *
  119.     ¥ #3
  120.     ¢ moveon
  121.  
  122.  
  123. _ move onto next command A = length of last command already
  124.  
  125. moveon    equ *
  126.     £ incpt
  127.     â relloop1
  128.  
  129. relend    equ *
  130.     ¬
  131.  
  132. _ Move the program pointer on a distance based on A.
  133. _ this routine also checks for end of program area.
  134.  
  135. incpt    equ * 
  136.     ì
  137.     Ç progptr
  138.     » progptr
  139.     ¥ progptr+1
  140.     Ç #0
  141.     » progptr+1
  142.  
  143. _ now check for end of program area
  144.     
  145.     æ newend+1
  146.     â exitinc1        _ not in top range yet, return c clear
  147.     à checkrst        _ same top address so check bottom
  148.     ä exitinc1        _ we are well past it, so carry set
  149. checkrst    equ *
  150.     ¥ progptr
  151.     æ newend
  152.  
  153. _ if progptr >= edadd then c=1 so we return c=1 to indicate overflow
  154.  
  155. exitinc1    equ *
  156.     ¬
  157.  
  158. _ find the length of the command
  159.  
  160. getlen    equ *
  161.     » neumonic
  162.     ü #15        _ get bottom 4 bits
  163.     æ #$0c
  164.     à byte3
  165.     æ #$0d
  166.     à byte3
  167.     æ #$0e
  168.     à byte3
  169.     æ #$0a
  170.     à byte1
  171.     æ #8
  172.     à byte1
  173.     æ #9
  174.     ê byte2
  175.     ¥ neumonic
  176.     ü #%00010000
  177.     ê byte3        _ top nibble is odd if value from and returned
  178.  
  179. _ falls through to be 2 bytes
  180.  
  181. byte2    equ *
  182.     ¥ #2
  183.     db  $2c
  184. byte1    ¥ #1
  185.     db  $2c
  186. byte3     ¥ #3
  187.     ¬
  188.  
  189. neumonic  db  0
  190.  
  191. _ check curradd to see if it is >=stadd and <=edadd
  192. _ c=0 means not in range
  193.  
  194. checklim    equ *
  195.     ¥ curradd+1
  196.     æ oldadd+1
  197.     â notin
  198.     à possibly
  199.     ä above
  200. possibly    equ *
  201.     ¥ curradd
  202.     æ oldadd
  203.     â notin
  204.  
  205. _ definitely above the lower limit
  206.  
  207. above    equ *
  208.     ¥ oldend+1
  209.     æ curradd+1
  210.     â notin
  211.     à maybe
  212.     ä yesin
  213. maybe    equ *
  214.     ¥ oldend
  215.     æ curradd        _ if c=0 here, not in range
  216.     
  217. yesin    equ *
  218. notin    equ *
  219.     ¬
  220.  
  221.     IEND    
  222.  
  223.  
  224.