Advertisement
wallyweek

DMPLOAD (ESXDOS) disassembly

Oct 2nd, 2017 (edited)
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Original file at
  2. ; http://dailly.blogspot.it/2017/06/zx-spectrum-next-bitmap-example.html
  3.  
  4. ; Disassembly of the file "bitmaps\BMPLOAD"
  5. ;
  6. ; BMP Port $123b
  7. ;     bit 0    -    Write enable. (banks in 16K from $0000-$3fff)
  8. ;     bit 1    -    bitmap ON
  9. ;     bit 4    -    Layer 2 below spectrum screen
  10. ;     bit 6-7  -    Which 16K bank to page into $0000-$3ffff
  11. ;
  12. ; On entry, HL = arguments
  13. ;
  14.  
  15. ;
  16. ; Since dot commands run at $2000, and the Layer 2 is paged into $0000-$3fff
  17. ; It needs to have some code above the lower 16K to actually copy into layer 2
  18. ; So copy up the "copy" routine, and it'll page in/out the layer 2 bank
  19. ;
  20. 2000 226221    ld      (HL_Save),hl     ; Store HL
  21. 2003 216421    ld      hl,UploadCode    ; Src  =
  22. 2006 110060    ld      de,6000h         ; dest = $6000
  23. 2009 011f00    ld      bc,001fh         ; size = 31 bytes
  24. 200c edb0      ldir    
  25.  
  26. 200e 2a6221    ld      hl,(HL_Save)     ; get HL back
  27. 2011 7c        ld      a,h
  28. 2012 b5        or      l                ; is hl 0?
  29. 2013 2008      jr      nz,201dh         ; if we have an argument, carry on
  30.  
  31. 2015 213121    ld      hl,2131h         ; get message
  32. 2018 cd1d21    call    PrintText        ; print the filename
  33. 201b 1823      jr      Exit             ; exit
  34.  
  35. ; Load file....?
  36. CopyFilename:
  37. 201d 112421    ld      de,FileName      ; "filename.ext" text - space to store filename?
  38. 2020 060c      ld      b,0ch            ; b = $0c (max length of allowed filename - no path it seems)
  39.  
  40. ; Copy, and validate characters in filename
  41. 2022 7e        ld      a,(hl)           ; first byte of filename
  42. 2023 fe3a      cp      3ah              ; is it a ":"?  End of filename
  43. 2025 2810      jr      z,EndFilename    ; if so end of filename  
  44. 2027 b7        or      a                ; 0?
  45. 2028 280d      jr      z,EndFilename    ; if so end of filename
  46. 202a fe0d      cp      0dh              ; newline?
  47. 202c 2809      jr      z,EndFilename    ; if so end of filename
  48. 202e cb7f      bit     7,a              ; over 127?
  49. 2030 2005      jr      nz,EndFilename   ; if so end of filename
  50. 2032 12        ld      (de),a           ; copy over to filename cache
  51. 2033 23        inc     hl               ; next src letter
  52. 2034 13        inc     de               ; next dest letter
  53. 2035 10eb      djnz    2022h            ; copy all
  54. EndFilename
  55. 2037 af        xor     a                ; Mark end of filename
  56. 2038 12        ld      (de),a           ; store filename
  57. 2039 dd212421  ld      ix,FileName      ; get filename base address
  58. 203d cd6220    call    LoadFile:
  59.  
  60. Exit:
  61. 2040 af        xor     a                ; no error
  62. 2041 c9        ret                      ; exit
  63.  
  64.  
  65. ; esxDOS detect if unit is ready
  66. DetectUnit:
  67. 2042 af        xor     a                ; Detect if unit is ready
  68. 2043 cf        rst     08h              ; call esxDOS
  69. 2044 89        db      $89              ; M_GETSETDRV
  70.  
  71. ; Open
  72. ; IX= Filename (ASCIIZ)
  73. ; B = FA_READ       ($01)
  74. ;     FA_APPEND     ($06)
  75. ;     FA_OVERWRITE  ($0C)
  76. ;
  77. OpenFile:
  78. 2045 dde5      push    ix               ; ix = filename
  79. 2047 e1        pop     hl               ; If a DOT command (rather than normal memory), uses HL not IX
  80. 2048 0601      ld      b,01h            ; b = FA_READ
  81. 204a 3e2a      ld      a,2ah            ; a = unknown  (a=0 for open)
  82. 204c cf        rst     08h              ; call esxDOS
  83. 204d 9a        db      $9a              ; F_Open
  84. 204e 325620    ld      (2056h),a        ; Store file handle  (self modify read from file code)
  85. 2051 c9        ret                      ;
  86.  
  87.  
  88. ; esxDOS command - Read from file - command $9d
  89. ; IX = address to load into
  90. ; BC = number of bytes to load
  91. ; A  = file handle
  92. ReadBytes:
  93. 2052 dde5      push    ix               ; IX = where to to store data
  94. 2054 e1        pop     hl               ; get address to load into
  95. 2055 3e00      ld      a,00h            ; $00 is self modified
  96. 2057 cf        rst     08h              ; call esxDOS
  97. 2058 9d        db      $9d              ; F_Read
  98. 2059 c9        ret    
  99.  
  100. ; esxDOS command - Close File - command $9b
  101. ; A = file handle
  102. CloseFile:
  103. 205a 3a5620    ld      a,(2056h)         ; Get open file handle
  104. 205d b7        or      a                 ; is it 0? (did it open)
  105. 205e c8        ret     z                 ; if file handle is 0, return
  106. 205f cf        rst     08h               ; Call esxDOS
  107. 2060 9b        db      $9b               ; F_Close
  108. 2061 c9        ret    
  109.  
  110. LoadFile:
  111. 2062 dde5      push    ix                ; remember filename
  112. 2064 cd4220    call    DetectUnit        ; detect unit and open...?!?!?
  113. 2067 dde1      pop     ix                ; get filename back
  114. 2069 cd4520    call    OpenFile          ; OpenFile - again??
  115. 206c dd21e720  ld      ix,BMPHeader      ; Read the BMP file header
  116. 2070 013600    ld      bc,0036h          ; read header ($36 bytes)
  117. 2073 cd5220    call    ReadBytes
  118. 2076 dd218321  ld      ix,BitMap         ; read block into $2183
  119. 207a 010004    ld      bc,0400h          ; read palette - 1024 bytes
  120. 207d cd5220    call    ReadBytes
  121.  
  122. ;
  123. ; Convert the 24bit palette into a simple RRRGGGBB format
  124. ;
  125. ConvertBMP:
  126. 2080 218321    ld      hl,BitMap         ; Get buffer address ($2183)
  127. 2083 11003f    ld      de,3f00h          ; Dest address of converted palette
  128. 2086 0600      ld      b,00h
  129.  
  130. ConvertionLoop:
  131. 2088 7e        ld      a,(hl)            ; get BLUE byte
  132. 2089 23        inc     hl                ; move on to green
  133. 208a c620      add     a,20h             ; brighten up a bit? (blue is always pretty dark??)
  134. 208c 3002      jr      nc,SkipSatB       ; overflow?
  135. 208e 3eff      ld      a,0ffh            ; if overflow, then saturate to $FF
  136.  
  137. SkipSatB:
  138. 2090 1f        rra                       ; get top 2 bits only  RRRGGGBB
  139. 2091 1f        rra    
  140. 2092 1f        rra    
  141. 2093 1f        rra    
  142. 2094 1f        rra    
  143. 2095 1f        rra    
  144. 2096 e603      and     03h               ; and store them at the bottom
  145. 2098 4f        ld      c,a               ; c holds current byte
  146.  
  147. 2099 7e        ld      a,(hl)            ; get GREEN
  148. 209a 23        inc     hl                ; move onto red
  149. 209b c610      add     a,10h             ; brighten up a bit as well
  150. 209d 3002      jr      nc,SkipSatG       ; if no overflow, skip saturate
  151. 209f 3eff      ld      a,0ffh
  152.  
  153. SkipSatG:
  154. 20a1 1f        rra                       ; get 3 bits of green into right place
  155. 20a2 1f        rra    
  156. 20a3 1f        rra    
  157. 20a4 e61c      and     1ch               ; mask off remaining lower bits
  158. 20a6 b1        or      c                 ; merge with output byte
  159. 20a7 4f        ld      c,a               ; store into output
  160.  
  161. 20a8 7e        ld      a,(hl)            ; get RED
  162. 20a9 23        inc     hl                ; move to next byte of colour (assuming alpha)
  163. 20aa c610      add     a,10h             ; brighten up a bit
  164. 20ac 3002      jr      nc,SkipSatR       ; no overflow?
  165. 20ae 3eff      ld      a,0ffh            ; Saturate to $FF
  166.  
  167. SkipSatR
  168. 20b0 e6e0      and     0e0h              ; keep top 3 bits
  169. 20b2 b1        or      c                 ; merge with output pixel
  170. 20b3 12        ld      (de),a            ; store converted pixel
  171. 20b4 13        inc     de                ; move to next ouput pixel
  172. 20b5 23        inc     hl                ; move to next BGRA pixel
  173. 20b6 10d0      djnz    ConvertionLoop    ; c = pixel....?!?!?!
  174.  
  175. 20b8 06c0      ld      b,0c0h            ; bc=$c000
  176.  
  177. ConvertUploadLoop:
  178. 20ba c5        push    bc
  179. 20bb dd21003e  ld      ix,3e00h          ; $3e00 = Destination address
  180. 20bf 010001    ld      bc,0100h          ; read 256 bytes of data
  181. 20c2 cd5220    call    ReadBytes         ; Read from file
  182.  
  183. ;
  184. ; convert 256 value palette index into actual RGB byte pixel using palette lookup
  185. ;
  186. 20c5 2e00      ld      l,00h             ; l = xx (loop counter)
  187.  
  188. CopyLoop:
  189. 20c7 263e      ld      h,3eh             ; hl = $3exx
  190. 20c9 5e        ld      e,(hl)            ; e = Get palette index
  191. 20ca 163f      ld      d,3fh             ; d = $3f palette base address - 256 byte aligned
  192. 20cc 1a        ld      a,(de)            ; a = palette value (24bit converted downto 8bit)
  193. 20cd 265b      ld      h,5bh             ; hl = $5bxx converted 256 byte buffer
  194. 20cf 77        ld      (hl),a            ; ($5bxx) = converted colour pixel
  195. 20d0 263e      ld      h,3eh             ; hl = $3e00
  196. 20d2 2c        inc     l                 ; do 256 bytes of this....
  197. 20d3 20f2      jr      nz,CopyLoop
  198.  
  199. 20d5 c1        pop     bc                ; bc = $c000
  200. 20d6 c5        push    bc
  201. 20d7 cd0060    call    6000h             ; block transfer 256 bytes of the bitmap
  202. 20da c1        pop     bc
  203. 20db 10dd      djnz    ConvertUploadLoop
  204. 20dd 013b12    ld      bc,123bh          ; Bitmap port
  205. 20e0 3e02      ld      a,02h             ; 2 = enable and visible
  206. 20e2 ed79      out     (c),a             ; switch bitmap layer 2 on
  207. 20e4 c35a20    jp      205ah
  208.  
  209. BMPHeader:     ds   54                   ; $20e7 to $211c
  210.  
  211. PrintText:
  212. 211d 7e        ld      a,(hl)            ; get character
  213. 211e 23        inc     hl                ; move to next one
  214. 211f b7        or      a                 ; is this 0?
  215. 2120 c8        ret     z                 ; if so... end of string
  216. 2121 d7        rst     10h               ; outchr()
  217. 2122 18f9      jr      211dh             ; print all characters
  218.  
  219. ;
  220. ; Looks like data of some kinds
  221. ;
  222. FileName: db  "filename.ext",0
  223. Message:  db  ".picload  to load image to background",$d,$00
  224. HL_Save   dw  0
  225.  
  226. ;
  227. ; Copied up to $6000
  228. ;
  229. UploadCode:
  230. 2164 05        dec     b                ; b = upper byte of memory address
  231. 2165 78        ld      a,b              ; get 256 byte page into a
  232. 2166 e63f      and     3fh              ; ignore top bits
  233. 2168 57        ld      d,a              ; de=$0000-$3ffff
  234. 2169 1e00      ld      e,00h            ; Page bitmap block into lower 16K
  235. 216b 78        ld      a,b
  236. 216c e6c0      and     0c0h             ; get the 16K bank to page
  237. 216e f601      or      01h              ; OR in bank active bit
  238. 2170 013b12    ld      bc,123bh         ; bitmap register
  239. 2173 ed79      out     (c),a            ; map bank into memory perhaps?
  240. 2175 21005b    ld      hl,5b00h         ; $5b00 src image chunk
  241. 2178 010001    ld      bc,0100h         ; 256 byte copy (one line)
  242. 217b edb0      ldir                     ; copy up  (de=dest)
  243. 217d 013b12    ld      bc,123bh         ; bitmap register
  244. 2180 ed69      out     (c),l            ; l=0, disable current bank and screen
  245. 2182 c9        ret    
  246.  
  247. BitMap:
  248. 2183 00        nop                      ; file is loaded into here....
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement