Advertisement
wallyweek

TR-DOS example

Nov 23rd, 2022 (edited)
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. 15 MACHINE CODE PROGRAMMING
  2.  
  3. The inclusion of TRDOS routines in machine code programs are
  4. relativey straightforward.
  5.  
  6. There are 3 elements required for the program:
  7.  
  8. (1) The machine code equivalent of the BASIC TRDOS command.
  9. (2) The machine code routine to implement 1 above.
  10. (3) The machine code routine to restore the system to its original
  11. state before calling and executing the command.
  12.  
  13. The actual memory locations used will depend upon the program as a
  14. whole. For the purpose of this example the location of the
  15. routines will be at 49000 for the SAVE, at 49500 for the LOAD and
  16. at 50000 for the instructions calling them. Thus item 1 will be at
  17. either 49000 or 49500 and items 2 and 3 at 50000.
  18.  
  19. EXAMPLE:
  20.  
  21. Address Code Basic Comment
  22.  
  23. 49000 234 REM Codes as in Appx A of Spectrum
  24. 49001 58 : manual
  25. 49002 248 SAVE
  26. 49003 34 "
  27. 49004 69 E
  28. 49005 120 x
  29. 49006 97 a
  30. 49007 109 m File name "Example"
  31. 49008 112 p
  32. 49009 108 l
  33. 49010 101 e
  34. 49011 34 "
  35. 49012 13 ENTER Always end with ENTER
  36.  
  37. The code for the LOAD commences at 49500 and is eaxctly the same
  38. as above except that address 49502 will contain 239 (LOAD) instead
  39. of 248 (SAVE).
  40.  
  41. These two routines, LOAD, and SAVE can be located anywhere, but
  42. the initiator which we are locating at 50000 requires changing at
  43. addresses 50007-50008 (Save routine address) and 50025 - 50026
  44. (LOAD routine address) to point to the new addresses.
  45.  
  46. To relocate, the initiator itself requires reassembly. For that
  47. reason the Z80 mnemonics only are given below.
  48.  
  49. CHADD EQU 23645 Location of SOS variable CHADD
  50. ORG XXXXX XXXX=address of this code
  51. LD HL,(CHADD) Start to save true CHADD
  52. LD (TEMP), HL Temporary store of true CHADD
  53. LD HL,49000 Address of SAVE routine
  54. LD (CHADD),HL CHADD now points to our routine
  55. CALL 15363 ENTER TRDOS SAVE via chadd
  56. JP BACK Jump to program point from which
  57. the whole routine was called
  58. LD HL,(CHADD)
  59. LD (TEMP),HL The routine for LOAD now repeats
  60. LD HL,49500 the above with just the address
  61. LD (CHADD),HL changed.
  62. CALL 15363
  63. BACK LD HL,(TEMP) Start to restore CHADD
  64. LD (CHADD),HL Reload original CHADD
  65. RET Return from where you came
  66. TEMP Label allocating memory for
  67. temporary storage
  68.  
  69. The whole routine pointing to both the SAVE and LOAD routines,
  70. together with the "return to point of entry" ending routine
  71. occupies only 47 bytes.
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement