Advertisement
wallyweek

ESXDOS hooks (incomplete)

Oct 2nd, 2017 (edited)
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; original file at
  2. ; https://github.com/Utodev/ZXUC/blob/master/zxuc.asm
  3.  
  4. ;ZXUC (C) Uto 2017
  5.  
  6. ; --- ESXDOS FUNCTIONS
  7.       M_GETSETDRV   equ   $89
  8.       F_OPEN   equ   $9a
  9.       F_CLOSE   equ   $9b
  10.       F_READ   equ   $9d
  11.       F_WRITE equ $9e
  12. ; --- FILE OPEN MODES
  13.       FA_READ   equ   $01
  14. ; --- ZXUNO details
  15.       zxuno_port equ 64571
  16.       REGISTERS_TO_LOAD_COUNT equ FHandle - RegistersToLoad
  17.  
  18. org $2000
  19.  
  20. Main:
  21.  
  22. ;---- Check if params
  23.  
  24.       ld a,h
  25.       or l
  26.       jr nz, loadConfig
  27.  
  28. ; ----------------------------
  29. ; +++ NO PARAMS - OPEN GUI +++
  30. ; ----------------------------
  31.  
  32. ; --- Set default disk    
  33.       xor a
  34.       rst $08
  35.       db M_GETSETDRV
  36.       ret c
  37.       ld (UnoD +1), A ; Save current drive just in case UnoDOs is being used
  38. ; --- Open ZXCU.BIN file for ESXDOS
  39.       ld b, FA_READ  
  40.       ld hl, zxucbinfile  
  41.       rst $08
  42.       db F_OPEN      
  43.       jr nc, load
  44. ; --- Open ZXCU.BIN file for UnoDOS
  45. UnoD  ld a, 0
  46.       ld b, FA_READ  
  47.       ld hl, zxucdosfile  
  48.       rst $08
  49.       db F_OPEN      
  50.       jr nc, load
  51. ; --- Load ZXCU.BIN at address 45000
  52. load  ld (FHandle),a
  53.       ld HL, 45000
  54.       ld bc, 16384   ; bc=file length ,in excess just to be sure
  55.       ld a,(FHandle)
  56.       rst $08
  57.       db F_READ      ; read file
  58.       ret c
  59. ; --- Close file      
  60.       ld a,(FHandle)
  61.       rst $08
  62.       db F_CLOSE
  63.       ret c
  64. ; --- Jump to address 45000 forcing exit from ESXDOS ROM so standard ROM is avaliable
  65.       rst $18
  66.       dw 45000
  67.       ret
  68.  
  69. ; --------------------------------------------------
  70. ; +++ LOAD A CONFIGURATION FILE - DON'T OPEN GUI +++
  71. ; --------------------------------------------------
  72.  
  73. loadConfig:
  74. ; --- Copy param to filename position
  75.       ld b, 8
  76.       ld de, cfgfile
  77. filenameLoop:      
  78.       ld a, (hl)
  79.       cp ':'
  80.       jr z, addZero  ; exit if ':' found
  81.       cp $0D
  82.       jr z, addZero  ; exit if carriage return found
  83.       ld (de), a
  84.       dec b
  85.       jp pe, loadFile; exit if already 8 characters
  86.       inc de
  87.       inc hl
  88.       jp filenameLoop
  89. addZero:   ; name shorter than 8 characters, set zero for ASCIIZ string
  90.       xor a
  91.       ld (de),a
  92. loadFile:
  93. ; --- Set default disk    
  94.       xor a
  95.       rst $08
  96.       db M_GETSETDRV
  97.       ret c
  98. ; --- Open cfg file      
  99.       ld hl, cfgpath  
  100.       ld b, FA_READ  
  101.       rst $08
  102.       db F_OPEN      
  103.       ret C
  104. ; --- Load data at cfgbuffer
  105.       ld (FHandle),a
  106.       ld hl, cfgbuffer
  107.       ld bc, REGISTERS_TO_LOAD_COUNT
  108.       rst $08
  109.       db F_READ      ; Leer archivo    
  110.       ret C
  111. ; --- Close file      
  112.       ld a,(FHandle)
  113.       rst $08
  114.       db F_CLOSE
  115.       ret c
  116.  
  117. ; --- Write config to ZX-Uno registers
  118.       ld hl, cfgbuffer
  119.       ld bc, zxuno_port
  120.       ld a, REGISTERS_TO_LOAD_COUNT
  121.       ld de, RegistersToLoad
  122. setRegsLoop:
  123.       push af                        ; Preserve record count
  124.       ld a, (de)                     ; Get first record to save  
  125.       inc de                         ; Point to next one in the list
  126.       out (c), a                     ; Select record
  127.       inc b                          ; Point to ZX-Uno data port (non casually, 256 bytes above the other one)
  128.       ld a, (hl)
  129.       out (c), a
  130.       inc hl                         ; Move pointer to buffer as well
  131.       dec b                          ; Point again to ZX-Un select port  
  132.       pop af                         ; Restore record count
  133.       dec a                          
  134.       or a
  135.       ret z                          ; Dec count and if zero, return
  136.       jr setRegsLoop
  137.       ret
  138.  
  139.  
  140.  
  141.  
  142. ;--- Variables
  143. ; IMPORTANT: NEVER EVER CHANGE THE ORDER OF THESE RECORDS, IF YOU HAVE TO ADD NEW ONE, ADD IT AS LAST RECORD INSTEAD OF INSERTING IT TO KEEP
  144. ;            NUMERIC ORDER. OTHERWISE, WHEN LOADING OLD SAVED CONFIGS VALUES FOR SOME ZX-UNO RECORDS WILL BE LOADED INTO DIFFERENT ONES
  145. RegistersToLoad: db $00, $06, $0B,$0E, $0F,$80, $81, $82, $83, $84, $85
  146. FHandle: db 0
  147. zxucbinfile: db "/BIN/ZXUC.BIN"
  148.              db 0
  149. zxucdosfile: db "/DOS/ZXUC.BIN"
  150.              db 0
  151. cfgpath: db "/SYS/CONFIG/ZXUCCFG/" ; Config files should be at /SYS/CONFIG and that folder should exist even for UnoDOS
  152. cfgfile: ds 8
  153.          db 0  
  154. cfgbuffer: ds 256
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement