Guest User

Untitled

a guest
Apr 11th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ROM0:20DA 7B               ld a,e ; Load LSB of destination bank into E
  2. ROM0:20DB EA 97 D0         ld (d097),a ; Load A into WRA1:D097
  3.  
  4. ROM0:20DE 7A               ld a,d ; Load MSB of destination bank into D
  5. ROM0:20DF EA 98 D0         ld (d098),a ; Load A into WRA1:D098
  6.  
  7. ROM0:20E2 7E               ld a,(hl) ; Read command
  8.  
  9. ROM0:20E3 FE FF            cp a,ff ; If the command is 0xFF (end stream)
  10. ROM0:20E5 C8               ret z ; Return to the caller
  11.  
  12. ROM0:20E6 E6 E0            and a,e0 ; Test for an extended command (0x00-0xFE)
  13. ROM0:20E8 FE E0            cp a,e0 ; Is this an extended command?
  14. ROM0:20EA 20 10            jr nz,20fc ; If it isn't, go to 20FC
  15.  
  16. ; 0xE0-0xFE Command (ExtCommand)
  17. ; Multiplies a command up to 32 times.
  18.  
  19. ROM0:20EC 7E               ld a,(hl) ; Read byte, do not increment ROM pointer
  20. ROM0:20ED 87               add a ; ?
  21. ROM0:20EE 87               add a ; ?
  22. ROM0:20EF 87               add a ; ?
  23. ROM0:20F0 E6 E0            and a,e0 ; Get only the number of bytes
  24.  
  25. ROM0:20F2 F5               push af ; Save AF
  26. ROM0:20F3 2A               ldi a,(hl) ; Read byte, increment ROM pointer
  27. ROM0:20F4 E6 03            and a,03 ; Keep only the last three bytes
  28. ROM0:20F6 47               ld b,a ; Set B to this number
  29. ROM0:20F7 2A               ldi a,(hl) ; Read byte, increment ROM pointer
  30. ROM0:20F8 4F               ld c,a ; Load C with byte read
  31. ROM0:20F9 03               inc bc ; Add one to the number of bytes
  32. ROM0:20FA 18 08            jr 2104 ; Continue inside ParseFirstOrderCommand
  33.  
  34. ; ParseFirstOrderCommand
  35. ; Parses first-order commands and passes second-order commands to
  36. ; ParseSecondOrderCommmand.
  37.  
  38. ROM0:20FC F5               push af ; Save AF
  39. ROM0:20FD 2A               ldi a,(hl) ; Read byte, increment ROM pointer
  40. ROM0:20FE E6 1F            and a,1f ; Get only the number of bytes
  41. ROM0:2100 4F               ld c,a ; Load number of bytes into C
  42. ROM0:2101 06 00            ld b,00 ; Load B with 0
  43. ROM0:2103 0C               inc c ; Increment C (?)
  44. ROM0:2104 04               inc b ; Increment B (?)
  45. ROM0:2105 0C               inc c ; Increment C (?)
  46. ROM0:2106 F1               pop af ; Restore AF
  47.  
  48. ROM0:2107 CB 7F            bit 7,a ; 2nd-order command (> 80)?
  49. ROM0:2109 20 49            jr nz,2154 ; If so go to 2154, else
  50.  
  51. ROM0:210B FE 20            cp a,20 ; Check if command = 0x20
  52. ROM0:210D 28 15            jr z,2124 ; Go to 0x20 processor at 2124, else
  53.  
  54. ROM0:210F FE 40            cp a,40 ; Check if command = 0x40
  55. ROM0:2111 28 1E            jr z,2131 ; Go to 0x40 processor at 2131, else
  56.  
  57. ROM0:2113 FE 60            cp a,60 ; Check if command = 0x60
  58. ROM0:2115 28 2F            jr z,2146 ; Go to 0x60 processor at 2146, else
  59.  
  60. ; 0x00-0x1F Command (ByteCopy)
  61. ;
  62. ; Directly copies (# + 1) bytes.
  63.  
  64.  
  65. ROM0:2117 0D               dec c ; Decrement C
  66. ROM0:2118 20 04            jr nz,211e ; If C != 0 then go to 211E
  67.  
  68. ROM0:211A 05               dec b ; Decrement B
  69. ROM0:211B CA E2 20         jp z,20e2 If B = 0 return to 20E2 ("Read command")
  70.  
  71. ROM0:211E 2A               ldi a,(hl) ; Read byte, increment ROM pointer
  72. ROM0:211F CD 99 D0         call d099 ; Call RAM write routine
  73. ROM0:2122 18 F3            jr 2117 ; Jump back to 2117
  74.  
  75. ; 0x20-0x3F Command (ByteFill)
  76. ;
  77. ; Fills (# + 1) bytes with next byte's value.
  78.  
  79. ROM0:2124 2A               ldi a,(hl) ; Read byte, increment ROM pointer
  80. ROM0:2125 0D               dec c ; Decrement C
  81. ROM0:2126 20 04            jr nz,212c ; If C != 0 then go to 212C
  82. ROM0:2128 05               dec b ; Decrement B
  83. ROM0:2129 CA E2 20         jp z,20e2 ; If B = 0 return to 20E2 ("Read command")
  84. ROM0:212C CD 99 D0         call d099 ; Call RAM write routine
  85. ROM0:212F 18 F4            jr 2125 ; Jump back to 2125
  86.  
  87. ; 0x40-0x5F Command (WordFill)
  88. ;
  89. ; Fills (# + 1) words with next word's value.
  90.  
  91. ROM0:2131 0D               dec c ; Decrement C
  92. ROM0:2132 20 04            jr nz,2138 ; If C != 0 then go to 2138
  93. ROM0:2134 05               dec b ; Decrement B
  94. ROM0:2135 CA 42 21         jp z,2142 ; If B = 0 go to 2142
  95.  
  96. ROM0:2138 2A               ldi a,(hl) ; Read byte, increment ROM pointer
  97. ROM0:2139 CD 99 D0         call d099 ; Call RAM write routine
  98. ROM0:213C 3A               ldd a,(hl) ; Read byte, decrement ROM pointer
  99. ROM0:213D CD 99 D0         call d099 ; Call RAM write routine
  100. ROM0:2140 18 EF            jr 2131 ; Jump back to 2131
  101.  
  102. ROM0:2142 23               inc hl ; Increment ROM pointer by one word
  103. ROM0:2143 23               inc hl
  104. ROM0:2144 18 9C            jr 20e2 ; return to 20E2 ("Read command")
  105.  
  106. ; 0x60-0x7F Command (IncrementalFill)
  107. ;
  108. ; Fills (# + 1) bytes with starting byte + an incrementing value.
  109.  
  110. ROM0:2146 2A               ldi a,(hl) ; Read byte, increment ROM pointer
  111. ROM0:2147 0D               dec c ; Decrement C
  112. ROM0:2148 20 04            jr nz,214e ; If C != 0 then go to 214E
  113. ROM0:214A 05               dec b ; Decrement B
  114. ROM0:214B CA E2 20         jp z,20e2 ; If B = 0 return to 20E2 ("Read command")
  115. ROM0:214E CD 99 D0         call d099 ; Call RAM write routine
  116. ROM0:2151 3C               inc a ; Increment A
  117. ROM0:2152 18 F3            jr 2147 ; Jump back to 2147
  118.  
  119. ; ParseSecondOrderCommmand
  120. ; Parses second-order commands.
  121.  
  122. ROM0:2154 E5               push hl ; Save HL
  123. ROM0:2155 F5               push af ; Save AF
  124.  
  125. ROM0:2156 2A               ldi a,(hl) ; Read byte, increment ROM pointer
  126. ROM0:2157 6E               ld l,(hl) ; Read byte into low ROM pointer
  127. ROM0:2158 67               ld h,a ; Load high ROM pointer into A
  128. ROM0:2159 FA 97 D0         ld a,(d097) ; Save A to D097
  129. ROM0:215C 85               add l ; Add/subtract A to low ROM pointer
  130. ROM0:215D 6F               ld l,a ; Load low ROM pointer into A
  131. ROM0:215E FA 98 D0         ld a,(d098) ; Save A to D098
  132. ROM0:2161 8C               adc h ; add A with carry to high ROM pointer
  133. ROM0:2162 67               ld h,a ; load high ROM pointer into A
  134. ROM0:2163 F1               pop af ; Restore AF
  135. ROM0:2164 FE 80            cp a,80 ; Check if command = 0x80
  136. ROM0:2166 28 08            jr z,2170 ; Go to 0x80 processor at 2170, else
  137. ROM0:2168 FE A0            cp a,a0 ; Check if command = 0xA0
  138. ROM0:216A 28 0F            jr z,217b ; Go to 0xA0 processor at 217B, else
  139. ROM0:216C FE C0            cp a,c0 ; Check if command = 0xC0
  140. ROM0:216E 28 23            jr z,2193 ; Go to 0xC0 processor at 2193
  141.  
  142. ; 0x80-0x9F (MemoryCopy)
  143. ;
  144. ; Copies (# + 1) bytes from the address provided in the next two bytes.
  145.  
  146. ROM0:2170 0D               dec c ; Decrement C
  147. ROM0:2171 20 03            jr nz,2176 ; If C != 0 then go to 2176
  148. ROM0:2173 05               dec b ; Decrement B
  149. ROM0:2174 28 29            jr z,219f ; If B = 0 go to 219F
  150. ROM0:2176 2A               ldi a,(hl) ; Read byte, increment ROM pointer
  151. ROM0:2177 12               ld (de),a ; Load DE with A
  152. ROM0:2178 13               inc de ; Increment DE
  153. ROM0:2179 18 F5            jr 2170 ; Jump back to 2170
  154.  
  155. ; 0xA0-0xBF: (MemoryCopyEOR)
  156. ;
  157. ; Copies (# + 1) bytes from the address provided in the next two bytes,
  158. ; and EORs the data with 0xFF
  159.  
  160. ROM0:217B 0D               dec c ; Decrement C
  161. ROM0:217C 20 04            jr nz,2182 ; If C != 0 then go to 2182
  162. ROM0:217E 05               dec b ; Decrement B
  163. ROM0:217F CA 9F 21         jp z,219f ; If B = 0 go to 219F
  164. ROM0:2182 2A               ldi a,(hl) ; Read byte, increment ROM pointer
  165. ROM0:2183 C5               push bc ; Save BC
  166. ROM0:2184 01 08 00         ld bc,0008 ; Number of times to rotate
  167. ROM0:2187 1F               rra ; Rotate A right
  168. ROM0:2188 CB 10            rl b ; Rotate B left
  169. ROM0:218A 0D               dec c ; Decrement C
  170. ROM0:218B 20 FA            jr nz,2187 ; If C != 0 then go to 2187
  171. ROM0:218D 78               ld a,b ; Load A with B
  172. ROM0:218E C1               pop bc ; Restore BC
  173. ROM0:218F 12               ld (de),a ; Write A to destination
  174. ROM0:2190 13               inc de ; Incrememnt destination pointer
  175. ROM0:2191 18 E8            jr 217b ; Jump back to 217B
  176.  
  177. ; 0xC0-0xDF (ReverseCopy)
  178. ;
  179. ; Copies (# + 1) bytes in reverse order from the address provided.
  180.  
  181. ROM0:2193 0D               dec c ; Decrement C
  182. ROM0:2194 20 04            jr nz,219a ; If C != 0 then go to 219A
  183. ROM0:2196 05               dec b ; Decrement B
  184. ROM0:2197 CA 9F 21         jp z,219f ; If B = 0 go to 219F
  185. ROM0:219A 3A               ldd a,(hl) ; Read byte, decrement ROM pointer
  186. ROM0:219B 12               ld (de),a ; Write A to destination
  187. ROM0:219C 13               inc de ; Incrememnt destination pointer
  188. ROM0:219D 18 F4            jr 2193 ; Jump back to 2193
  189.  
  190. ; Exit ParseSecondOrderCommmand
  191.  
  192. ROM0:219F E1               pop hl ; restore ROM pointer
  193. ROM0:21A0 23               inc hl ; Increment ROM pointer by one word
  194. ROM0:21A1 23               inc hl
  195. ROM0:21A2 C3 E2 20         jp 20e2 ; Return to 20E2 ("Read command")
  196.  
  197. ; RAM Copy Routine
  198. ;
  199. ; Written into RAM at D099-D09F at startup.
  200. ; Responsible for writing bytes to RAM at destination (DE).
  201. ; A is the byte to write.
  202. ; DE is the destination address.
  203.  
  204. WRA1:D099 00               nop ; Padding
  205. WRA1:D09A 00               nop ; Padding
  206. WRA1:D09B 12               ld (de),a ; Write A to destination
  207. WRA1:D09C 00               nop ; Padding
  208. WRA1:D09D 00               nop ; Padding
  209. WRA1:D09E 13               inc de ; Incrememnt destination pointer
  210. WRA1:D09F C9               ret ; Return to caller
Add Comment
Please, Sign In to add comment