Advertisement
SevenFFF

ZX Spectrum Next Multiframe Copper Program

Feb 11th, 2020
584
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Assembles with Zeus Next, from http://www.desdes.com/products/oldfiles/zeustest.exe
  2.  
  3. zeusemulate             "Next", "RAW"
  4.  
  5. org $8000
  6.  
  7. SetupCopperFlash.       proc
  8.                         CopperControl(%00, 0)                           ; Stop the copper and position to program index 0
  9.                         ld b, CopperFlash.Count                         ; Count is the number of words in the program,
  10.                         ld hl, CopperFlash.Program                      ; coded like this so b is 180, which is < 256
  11. ProgramLoop:            ld a, (hl)                                      ; Read pairs of copper instruction bytes
  12.                         nextreg $60, a                                  ; And write them to the copper program register
  13.                         inc hl
  14.                         ld a, (hl)
  15.                         nextreg $60, a
  16.                         inc hl
  17.                         djnz ProgramLoop                                ; DJNZ is why b is better < 256
  18.                         ld bc, CopperFlash.Empty                        ; Empty is the count of unused instruction pairs
  19. EmptyLoop:              nextreg $60, 0                                  ; Write NOPs for every unused byte
  20.                         dec bc                                          ; in the 1024-instruction program
  21.                         ld a, b                                         ; (total 2048 bytes)
  22.                         or c
  23.                         jp nz, EmptyLoop                                ; Again, b is 166, which is < 256
  24.                         CopperControl(%01, 0)                           ; Finally turn the copper on. It will run
  25.                         ret                      ; without attention as long as NXtel is running.
  26. pend
  27.  
  28.  
  29.  
  30. CopperFlash             proc Program:
  31.                         CopperWait(0, 192, 32)                          ; Wait for 32 frames, ending on line 192
  32.                         CopperMove($43, %0 001 000 0, 1)                ; Set Layer 2 primary palette, incrementing
  33.                         CopperMove($40, 64, 1)                          ; Start writing palette entries at index 64
  34.                         CopperPalette(64, 8)                            ; Redefine as background (8 of each colour)
  35.                         CopperWait(0, 192, 16)                          ; Wait for another 16 frames, ending on line 192
  36.                         CopperMove($43, %0 001 000 0, 1)                ; Set Layer 2 primary palette, incrementing
  37.                         CopperMove($40, 64, 1)                          ; Start writing palette entries at index 64
  38.                         CopperPalette(64, 1)                            ; Redefine as foreground (1 of each colour)
  39.  
  40.   Size  equ $-Program                                                   ; This program will run forever,
  41.   Count equ Size/2                                                      ; restarting automatically every 48 frames.
  42.   Empty equ 2048-Size
  43. pend
  44.  
  45.  
  46.  
  47. CopperControl           macro(Command, Position)
  48.                         nextreg $62, ((Command & %11) << 6) | ((high Position) & %111)
  49.                         nextreg $61, low Position
  50. mend
  51.  
  52.  
  53.  
  54. CopperNOP               macro(Iterations)
  55.                         ds Iterations*2
  56. mend
  57.  
  58.  
  59.  
  60. CopperHalt              macro()
  61.                         dw $FFFF
  62. mend
  63.  
  64.  
  65.  
  66. CopperWait              macro(X, Y, Frames)
  67.                         for n = Y+Frames-1 to Y step -1
  68.                           db %10000000 | ((X & %111111) << 1) | ((high n) & %1)
  69.                           db low n
  70.                         next ;n
  71. mend
  72.  
  73.  
  74.  
  75. CopperMove              macro(Reg, Val, Iterations)
  76.                         for n = 1 to Iterations
  77.                           db Reg & %01111111
  78.                           db Val & %11111111
  79.                         next ;n
  80. mend
  81.  
  82.  
  83.  
  84. CopperPalette           macro(Iterations, Each)
  85.                         for n = 0 to Iterations - 1
  86.                           db $41                        ; 8-bit palette register
  87.                           db TeletextColour(n / Each)   ; 8-bit teletext colour value (RRRGGGBB)
  88.                         next ;n
  89. mend
  90.  
  91.  
  92.  
  93. [[
  94. function TeletextColour(Value)
  95. begin
  96.   if (Value mod 8) = 0
  97.     return %000 000 00                                  ; 0  Black    The layer 2 primary palette repeats these
  98.   if (Value mod 8) = 1
  99.     return %111 000 00                                  ; 1  Red      8 colours 32 times through indices 0..255.
  100.   if (Value mod 8) = 2
  101.     return %000 111 00                                  ; 2  Green
  102.   if (Value mod 8) = 3
  103.     return %111 111 00                                  ; 3  Yellow
  104.   if (Value mod 8) = 4
  105.     return %001 001 11                                  ; 4  Blue     Lightened for readability on black background.
  106.   if (Value mod 8) = 5
  107.     return %111 001 11                                  ; 5  Magenta  Uses $E7 because global transparency is $E3.
  108.   if (Value mod 8) = 6
  109.     return %000 111 11                                  ; 6  Cyan
  110.   return %111 111 11                                    ; 7  White
  111. end
  112. ]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement