?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1.     ; init ZX48 device, put machine code at $8000
  2.     DEVICE ZXSPECTRUM48 : ORG $8000
  3.  
  4.     RELOCATE_START
  5.  
  6.     dw      relocate_count
  7.     dw      relocate_size
  8.  
  9. vram_routine_bytes:                 ; relocatable label
  10.     ; like use case: "helper routine to be displaced at runtime to ULA VRAM"
  11.     DISP    vram_routine_bytes      ; error, no DISP for relocatable labels
  12.     DISP    $4000
  13. vram_routine:                       ; absolute label (and "$" should be absolute here too)
  14.     ld      hl,$-$300               ; should not relocate
  15.     ld      de,$+$800               ; should not relocate
  16.     ld      ix,vram_routine_bytes   ; should give relocate data for the physical location ($8000+ address)
  17.     jp      nz,vram_routine         ; should not relocate
  18.     jp      absolute1               ; should not relocate
  19.  
  20.     RELOCATE_END    ; error - can't finish relocate block with DISP block open
  21.  
  22.     ENT             ; end displacement routine
  23. vram_routine_bytes.size EQU $ - vram_routine_bytes  ; should be length
  24.  
  25.     ; use case: "dislocating the subroutine to target memory at runtime"
  26.     ld      hl,vram_routine_bytes   ; should relocate
  27.     ld      de,vram_routine         ; should not relocate
  28.     ld      bc,vram_routine_bytes.size  ; absolute size (not relocate)
  29.     ldir
  30.     call    vram_routine            ; should not relocate
  31.     jp      absolute1               ; should not relocate
  32.  
  33.     RELOCATE_END
  34.  
  35. absolute1:
  36.     jp      absolute1               ; should not relocate
  37.  
  38.     ENT                             ; error ENT without DISP
  39.  
  40.     RELOCATE_TABLE
  41.         ; 0C 80 15 80 ($800C, $8015)
  42.  
  43.     ; verify the actual machine code was placed at $8000 in virtual device memory
  44.     SAVEBIN "relocation_disp_inside.bin", $8000, $ - $8000
  45.  
  46.     ASSERT 2 == relocate_count
  47.     ASSERT 2*relocate_count == relocate_size
  48.     ASSERT 3 == __ERRORS__
  49.     ASSERT 0 == __WARNINGS__
  50.