Advertisement
wallyweek

More ESXDOS assembly reference

Sep 26th, 2019
701
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;
  2. ; Publicly available stuff..........
  3. ;
  4. ; esxDOS
  5. ;       setdrv  xor a
  6. ;       rst $08
  7. ;       db $89
  8. ;       a = drive
  9. ;       ret
  10. ;
  11. ;       fopen   ld      b,$01:db 33
  12. ;       fcreate ld      b,$0c:push ix:pop hl:ld a,42:rst $08:db $9a:ld (handle),a:ret
  13. ;       fread   push ix:pop hl:db 62
  14. ;       handle  db 0:or a:ret z:rst $08:db $9d:ret
  15. ;       fwrite  push ix:pop hl:ld a,(handle):or a:ret z:rst $08:db $9e:ret
  16. ;       fclose  ld      a,(handle):or a:ret z:rst $08:db $9b:ret
  17. ;       fseek   ld a,(handle):or a:ret z:rst $08:db $9f:ret
  18. ;       // Seek BCDE bytes. A=handle
  19. ;       //      L=mode:         0-from start of file
  20. ;       //                      1-forward from current position
  21. ;       //                      2-back from current position
  22. ;       // On return BCDE=current file pointer.
  23. ;       // Does not currently return bytes
  24. ;
  25. ;
  26.  
  27. M_GETSETDRV  equ $89
  28. F_OPEN       equ $9a
  29. F_CLOSE      equ $9b
  30. F_READ       equ $9d
  31. F_WRITE      equ $9e
  32. F_SEEK       equ $9f
  33.  
  34. FA_READ      equ $01
  35. FA_APPEND    equ $06
  36. FA_OVERWRITE equ $0C
  37.  
  38. ; *******************************************************************************************************
  39. ;
  40. ;   Get/Set the drive (get default drive)
  41. ;
  42. ; *******************************************************************************************************
  43. GetSetDrive:   
  44.         push    af  ; no idea what it uses....
  45.         push    bc
  46.         push    de
  47.         push    hl
  48.         push    ix
  49.  
  50.         xor a   ; set drive. 0 is default
  51.         rst $08
  52.         db  $89
  53.         ld  (DefaultDrive),a
  54.  
  55.         pop ix
  56.         pop hl
  57.         pop de
  58.         pop bc
  59.         pop af
  60.         ret
  61. DefaultDrive:   db  0
  62.  
  63. ; *******************************************************************************************************
  64. ;   Function:   Open a file read for reading/writing
  65. ;   In:     ix = filename
  66. ;           b  = Open filemode
  67. ;   ret     a  = handle, 0 on error
  68. ; *******************************************************************************************************
  69. fopen:      push    hl
  70.         push    ix
  71.         pop hl
  72.         ld  a,(DefaultDrive)
  73.         rst $08
  74.         db  F_OPEN
  75.         pop hl
  76.         ret
  77.  
  78.  
  79. ; *******************************************************************************************************
  80. ;   Function    Read bytes from the open file
  81. ;   In:     ix  = address to read into
  82. ;           bc  = amount to read
  83. ;   ret:        carry set = error
  84. ; *******************************************************************************************************
  85. fread:
  86.         or      a             ; is it zero?
  87.         ret     z             ; if so return       
  88.  
  89.             push    hl
  90.  
  91.             push    ix
  92.         pop hl
  93.         rst $08
  94.         db  F_READ
  95.  
  96.         pop hl
  97.         ret
  98.  
  99. ; *******************************************************************************************************
  100. ;   Function    Read bytes from the open file
  101. ;   In:     ix  = address to read into
  102. ;           bc  = amount to read
  103. ;   ret:        carry set = error
  104. ; *******************************************************************************************************
  105. fwrite:
  106.         or      a             ; is it zero?
  107.         ret     z             ; if so return       
  108.  
  109.             push    hl
  110.  
  111.             push    ix
  112.         pop hl
  113.         rst $08
  114.         db  F_WRITE
  115.  
  116.         pop hl
  117.         ret
  118.  
  119. ; *******************************************************************************************************
  120. ;   Function:   Close open file
  121. ;   In:     a  = handle
  122. ;   ret     a  = handle, 0 on error
  123. ; *******************************************************************************************************
  124. fclose:    
  125.         or      a             ; is it zero?
  126.                 ret     z             ; if so return       
  127.         rst $08
  128.         db  F_CLOSE
  129.         ret
  130.  
  131.  
  132.  
  133. ; *******************************************************************************************************
  134. ;   Function    Read bytes from the open file
  135. ;   In:     a   = file handle
  136. ;           L   = Seek mode (0=start, 1=rel, 2=-rel)
  137. ;           BCDE = bytes to seek
  138. ;   ret:        BCDE = file pos from start
  139. ; *******************************************************************************************************
  140. fseek:
  141.         push    ix
  142.         push    hl
  143.         rst $08
  144.         db  F_SEEK
  145.         pop hl
  146.         pop ix
  147.         ret
  148.  
  149. ; *******************************************************************************************************
  150. ; Init the file system
  151. ; *******************************************************************************************************
  152. InitFileSystem:
  153.         call    GetSetDrive
  154.         ret
  155.  
  156.  
  157. ; *******************************************************************************************************
  158. ; Function: Load a whole file into memory   (confirmed working on real machine)
  159. ; In:       hl = file data pointer
  160. ;       ix = address to load to
  161. ; *******************************************************************************************************
  162. Load:       call    GetSetDrive     ; need to do this each time?!?!?
  163.  
  164.         push    bc
  165.         push    de
  166.         push    af
  167.  
  168.  
  169.         ; get file size
  170.         ld  c,(hl)
  171.         inc l
  172.         ld  b,(hl)
  173.         inc l
  174.  
  175.         push    bc          ; store size
  176.         push    ix          ; store load address
  177.  
  178.  
  179.         push    hl          ; get name into ix
  180.                 pop ix
  181.                 ld      b,FA_READ       ; mode open for reading
  182.                 call    fOpen
  183.                 jr  c,@error_opening    ; carry set? so there was an error opening and A=error code
  184.                 cp  0           ; was file handle 0?
  185.                 jr  z,@error_opening    ; of so there was an error opening.
  186.  
  187.                 pop ix          ; get load address back
  188.                 pop bc          ; get size back
  189.  
  190.                 push    af          ; remember handle
  191.                 call    fread           ; read data from A to address IX of length BC                
  192.         jr  c,@error_reading
  193.  
  194.                 pop af          ; get handle back
  195.                 call    fClose          ; close file
  196.                 jr  c,@error_closing
  197.  
  198.             pop af          ; normal exit
  199.         pop de
  200.         pop bc
  201.         ret
  202.  
  203. ;
  204. ; On error, display error code an lock up so we can see it
  205. ;
  206. @error_opening:
  207.         pop ix
  208. @error_reading:    
  209.         pop bc  ; don't pop a, need error code
  210.  
  211. @error_closing:
  212. @NormalError:   pop bc  ; don't pop into A, return with error code
  213.         pop de
  214.         pop bc
  215.         ret
  216.  
  217.  
  218. ; *******************************************************************************************************
  219. ; Function: Load a whole file into memory   (confirmed working on real machine)
  220. ; In:       hl = file data pointer
  221. ;       ix = address to save from
  222. ;       bc = size
  223. ; *******************************************************************************************************
  224. Save:       call    GetSetDrive     ; need to do this each time?!?!?
  225.  
  226.         push    bc          ; store size
  227.         push    ix          ; store save address
  228.  
  229.  
  230.         push    hl          ; get name into ix
  231.                 pop ix
  232.                 ld      b,FA_OVERWRITE      ; mode open for writing
  233.                 call    fOpen
  234.                 jr  c,@error_opening    ; carry set? so there was an error opening and A=error code
  235.                 cp  0           ; was file handle 0?
  236.                 jr  z,@error_opening    ; of so there was an error opening.
  237.  
  238.                 pop ix          ; get save address back
  239.                 pop bc          ; get size back
  240.  
  241.                 push    af          ; remember handle
  242.                 call    fwrite          ; read data from A to address IX of length BC                
  243.         jr  c,@error
  244.  
  245.                 pop af          ; get handle back
  246.                 call    fClose          ; close file
  247. @error:
  248.         ret
  249.  
  250. ;
  251. ; On error, display error code an lock up so we can see it
  252. ;
  253. @error_opening:
  254.         pop ix
  255.         pop bc  ; don't pop a, need error code
  256.         ret
  257.  
  258. ; ******************************************************************************
  259. ; Function: Load a 256 colour bitmap directly into the screen
  260. ;       Once loaded, enable and display it
  261. ; In:       hl = file data pointer
  262. ; ******************************************************************************
  263. Load256Screen:
  264.         push    bc
  265.         push    de
  266.         push    ix
  267.         push    af
  268.  
  269.         ; ignore file length... it's set for this (should be 256*192)
  270.         inc hl
  271.         inc hl
  272.  
  273.         push    hl
  274.                 pop ix
  275.                 ld      b,FA_READ
  276.                 call    fOpen
  277.                 jr  c,@error_opening    ; error opening?
  278.                 cp  0
  279.                 jr  z,@error_opening    ; error opening?
  280.                 ld  (LoadHandle),a      ; store handle
  281.  
  282.  
  283.                 ld  e,3         ; number of blocks
  284.                 ld  a,1         ; first bank...
  285. @LoadAll:
  286.                 ld      bc, $123b
  287.                 out (c),a           ; bank in first bank
  288.                
  289.                 push    af
  290.  
  291.                 ld  a,(LoadHandle)
  292.                 ld  bc,64*256
  293.                 ld  ix,0
  294.                 call    fread
  295.  
  296.                 pop af
  297.                 add a,$40
  298.                 dec e
  299.                 jr  nz,@LoadAll
  300.  
  301.                 ld  a,(LoadHandle)
  302.                 call    fClose
  303.  
  304.                 ld      bc, $123b
  305.                 ld  a,2
  306.                 out (c),a                              
  307.                 jr  @SkipError
  308. @error_opening:
  309.         ld      a,5
  310.             out     ($fe),a
  311. @SkipError
  312.             pop af
  313.         pop ix
  314.         pop de
  315.         pop bc
  316.         ret
  317. LoadHandle  db  0
  318.  
  319.  
  320.  
  321. FileHandle  db  0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement