spectrum.fs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. start-microcode spectrum
  2. \ Interface:
  3. \ 4000-57FF Spectrum bitmap
  4. \ 5800-5AFF Spectrum attributes
  5. \ 7000 attribute lookup: 256 bytes. 64 colors of (paper, ink)
  6. \ 7100 pixel stretch, 16 bytes.
  7. : 1+ d# 1 + ;
  8. : 0= d# 0 = ;
  9. : 4* d# 4 * ;
  10. : 64mod h# 3f and ;
  11. : copy1 ( src dst -- src' dst' ) \ copy one byte
  12. over c@
  13. over c!
  14. 1+
  15. ;fallthru
  16. : n1+ ( a b -- a+1 b )
  17. swap 1+ swap ;
  18. \ copy attrs for line y
  19. \ dst is RAM_PAL or RAM_PAL+256
  20. : attrcopy ( y -- )
  21. dup 4* h# 5800 + swap ( src y )
  22. h# 8 and d# 32 * RAM_PAL + ( src dst )
  23. begin
  24. over c@ 64mod 4* h# 7000 + swap \ fetch and lookup attribute
  25. copy1 copy1 d# 4 + copy1 copy1 nip
  26. n1+
  27. dup h# ff and 0=
  28. until
  29. drop drop
  30. ;
  31. : stretch! ( dst a -- dst' ) \ expand 4 bit graphic a, write to dst
  32. h# f and
  33. h# 7100 + c@
  34. over c! 1+
  35. ;
  36. : byte ( src dst -- src' dst' )
  37. over c@ swap ( src a dst )
  38. over d# 4 rshift stretch!
  39. swap stretch! ( src dst' )
  40. swap h# 100 + swap \ down 1 line in spectrum video memory
  41. ;
  42. : byte4
  43. byte byte byte byte ;
  44. : pixelcopy ( y -- y )
  45. dup 64mod 4* h# 4000 +
  46. over h# c0 and d# 32 * + ( y src )
  47. begin
  48. dup
  49. dup 64mod d# 16 * RAM_CHR +
  50. byte4 byte4
  51. drop drop
  52. 1+
  53. dup h# 1f and 0=
  54. until drop
  55. ;
  56. \ Spectrum memory layout is a bit twisted
  57. \ line 0 4000, 4001, 4002
  58. \ 1 4100, 4101
  59. \ ...
  60. \ 8 4020
  61. \ ...
  62. \ 56 40e0, ... 40ff
  63. \ ...
  64. \ 63 47e0 47ff
  65. \ 64 4800
  66. \ 65 4900
  67. \ ...
  68. \ 191 57e0
  69. \ at line 0 can start work on 4020
  70. \ at line 8 can start work on 4040
  71. \ at line 16 can start work on 4060
  72. \ 56 4800
  73. \
  74. \ So in general, at line Y can start work on converting from:
  75. \ 4000 + (((Y+8) & 38) * 4) + (((y+8) & c0) * 32)
  76. : main
  77. d# 0
  78. begin
  79. begin dup d# 48 + YLINE c@ = until
  80. d# 8 + h# ff and
  81. dup attrcopy
  82. pixelcopy
  83. again
  84. ;
  85. end-microcode