Advertisement
Guest User

PROGRAM

a guest
Jan 21st, 2020
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.24 KB | None | 0 0
  1. #include "CPU_65202.CPU"
  2.  
  3.  
  4.  
  5. ROM_START = 0x000000
  6. IO_START = 0x000000
  7. RAM_START = ROM_START + 0x400
  8. DEFAULT_N_PAGE = RAM_START
  9. STACK_START = RAM_START + 0x200
  10.  
  11. STR_SPACE = RAM_START + 0x300
  12.  
  13. TERM = IO_START ; Serial Terminal
  14. KEYB = IO_START ; Serial Keyboard
  15. KEYS = IO_START + 1 ; Keyboard Status
  16. EXTR = IO_START + 1 ; Something else
  17.  
  18.  
  19. INT_VAR_0 = DEFAULT_N_PAGE
  20. INT_VAR_1 = DEFAULT_N_PAGE + 2
  21. INT_VAR_2 = DEFAULT_N_PAGE + 4
  22. INT_VAR_3 = DEFAULT_N_PAGE + 6
  23. INT_VAR_4 = DEFAULT_N_PAGE + 8
  24. INT_VAR_5 = DEFAULT_N_PAGE + 10
  25. INT_VAR_6 = DEFAULT_N_PAGE + 12
  26. INT_VAR_7 = DEFAULT_N_PAGE + 14
  27.  
  28. STR_PNT_0 = DEFAULT_N_PAGE + 0x80
  29. STR_PNT_1 = DEFAULT_N_PAGE + 0x80 + 3
  30. STR_PNT_2 = DEFAULT_N_PAGE + 0x80 + 6
  31. STR_PNT_3 = DEFAULT_N_PAGE + 0x80 + 9
  32.  
  33.  
  34.  
  35.  
  36.  
  37. ASCII_ZERO = 0x30
  38. ASCII_LF = 0x0A
  39.  
  40.  
  41.  
  42. INIT:
  43. DI
  44. LD A, 0x0000
  45. LD X, A
  46. LD Y, A
  47. LD SN, STACK_START[23:16]
  48. LD SP, STACK_START[15:0]
  49. LD N, DEFAULT_N_PAGE[23:8]
  50. LD ITP, INT_VECTORS
  51. CLF
  52. EI
  53. JMP START
  54.  
  55. INT_VECTORS:
  56. #d24 INT_HANDLER[23:0] ; INT Vector
  57. #d24 NMI_HANDLER[23:0] ; NMI Vector
  58.  
  59.  
  60. INT_HANDLER:
  61.  
  62. RET
  63.  
  64. NMI_HANDLER:
  65.  
  66. RET
  67.  
  68.  
  69. START:
  70.  
  71. LD [STR_PNT_0], STR_SPACE[23:16]
  72. LD [STR_PNT_0 + 1], STR_SPACE[15:8]
  73. LD [STR_PNT_0 + 2], STR_SPACE[7:0]
  74.  
  75. LD XL, ASCII_LF
  76.  
  77. CALL GET_STR
  78.  
  79. CALL PRINT_STR
  80.  
  81.  
  82. HALT
  83.  
  84.  
  85.  
  86.  
  87.  
  88. CNT_MEM_STR:
  89. ;#str "kB of Memory detected\n\0"
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96. CNT_MEM: ; Counts the amount of RAM in the system in kB (banked RAM ignored), starts from RAM_START, uses (INT_VAR_0) and the bottom half of INT_VAR_1
  97.  
  98. RET
  99.  
  100.  
  101. PRINT_STR: ; Prints a String to (TERM) from the address stored at (STR_PNT_0), Strings are Null Terminated
  102. DXO
  103. PUSH YL
  104. LD YL, 0x00
  105. .LOOP:
  106. LD AL, ([STR_PNT_0], Y)
  107. CMP 0x00
  108. JR Z .EXIT
  109. OUT (TERM), AL
  110. INC YL
  111. JR NO .LOOP
  112. LD AL, 0xFF
  113. POP YL
  114. RET
  115. .EXIT:
  116. LD AL, 0x00
  117. POP YL
  118. RET
  119.  
  120.  
  121. GET_STR: ; Stores a String from (KEYB) to Memory using the address stored at (STR_PNT_0) until the read byte equals XL, then it replaces that byte with 0x00
  122. DXO
  123. PUSH YL
  124. LD YL, 0x00
  125. .LOOP:
  126. .WAIT_DATA:
  127. IN AL, (KEYS)
  128. CMP XL
  129. JR Za .WAIT_DATA
  130. JR Z .EXIT
  131. LD ([STR_PNT_0], Y), AL
  132. INC YL
  133. JR NO .LOOP
  134. LD AL, 0xFF
  135. POP YL
  136. RET
  137. .EXIT:
  138. LD AL, 0x00
  139. LD ([STR_PNT_0], Y), AL
  140. POP YL
  141. RET
  142.  
  143.  
  144. CMP_STR: ; Compares 2 Strings from (STR_PNT_0) and (STR_PNT_1) until both strings end with 0x00 or one with 0x00 and the other with XL
  145.  
  146. RET
  147.  
  148.  
  149. INT8_STR: ; Converts an 8-bit Integer from the bottom half of INT_VAR_0 into a string stored at (STR_PNT_0), string is null-terminated
  150.  
  151. RET
  152.  
  153.  
  154. INT16_STR: ; Converts a 16-bit Integer from INT_VAR_0 into a string stored at (STR_PNT_0), string is null-terminated
  155.  
  156. RET
  157.  
  158.  
  159. IMUL_8: ; Multiplies 2 8-Bit Integers from the bottom half of INT_VAR_0 and INT_VAR_1 and stores the result in AL
  160.  
  161. RET
  162.  
  163.  
  164. IMUL_16: ; Multiplies 2 16-Bit Integers from INT_VAR_0 and INT_VAR_1 and stores the result in A
  165.  
  166. RET
  167.  
  168.  
  169. IDIV_8: ; Divides 2 8-Bit Integers from the bottom half of INT_VAR_0 and INT_VAR_1 (INT_VAR_0 / INT_VAR_1 = AL) and stores the result in AL (remainder in Y)
  170.  
  171. RET
  172.  
  173.  
  174. IDIV_16: ; Divides 2 16-Bit Integers from INT_VAR_0 and INT_VAR_1 (VAR_0 / VAR_1 = A) and stores the result in A (remainder in XY)
  175.  
  176. RET
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement