@@ -759,16 +759,25 @@ end
759759-- Misc Utilities
760760---- ----------------------------------------------
761761
762- function apple2 . GetDoubleHiresByte (row , col )
762+ function GetDHRByteAddress (row , col )
763763 local bank = col % 2
764764 col = col >> 1
765765 local aa = (row & 0xC0 ) >> 6
766766 local bbb = (row & 0x38 ) >> 3
767767 local ccc = (row & 0x07 )
768- local addr = 0x2000 + (aa * 0x28 ) + (bbb * 0x80 ) + (ccc * 0x400 ) + col
768+ return bank , 0x2000 + (aa * 0x28 ) + (bbb * 0x80 ) + (ccc * 0x400 ) + col
769+ end
770+
771+ function apple2 .GetDoubleHiresByte (row , col )
772+ local bank , addr = GetDHRByteAddress (row , col )
769773 return apple2 .ReadRAMDevice (addr + 0x10000 * (1 - bank ))
770774end
771775
776+ function apple2 .SetDoubleHiresByte (row , col , value )
777+ local bank , addr = GetDHRByteAddress (row , col )
778+ apple2 .WriteRAMDevice (addr + 0x10000 * (1 - bank ), value )
779+ end
780+
772781function apple2 .GrabTextScreen ()
773782 local is80 = apple2 .ReadSSW (" RD80VID" ) > 127
774783 local screen = " "
@@ -791,30 +800,28 @@ end
791800
792801---- ----------------------------------------------
793802
794- function apple2 .DHRDarkness ()
795- function SetDHRByte (col , row , value )
796- local bank = col % 2
797- col = col >> 1
798- local aa = (row & 0xC0 ) >> 6
799- local bbb = (row & 0x38 ) >> 3
800- local ccc = (row & 0x07 )
801- local addr = 0x2000 + (aa * 0x28 ) + (bbb * 0x80 ) + (ccc * 0x400 ) + col
802- apple2 .WriteRAMDevice (addr + 0x10000 * (1 - bank ), value )
803- end
804-
805- local bytes = {
806- {0x00 , 0x00 , 0x00 , 0x00 },
807- {0x08 , 0x11 , 0x22 , 0x44 },
808- {0x00 , 0x00 , 0x00 , 0x00 },
809- {0x22 , 0x44 , 0x08 , 0x11 },
810- }
803+ local darkness_bytes = {
804+ {0x00 , 0x00 , 0x00 , 0x00 },
805+ {0x08 , 0x11 , 0x22 , 0x44 },
806+ {0x00 , 0x00 , 0x00 , 0x00 },
807+ {0x22 , 0x44 , 0x08 , 0x11 },
808+ }
811809
810+ function apple2 .DHRDarkness ()
812811 for row = 0 ,191 do
813812 for col = 0 ,79 do
814- SetDHRByte (col , row , bytes [row % 4 + 1 ][col % 4 + 1 ])
813+ local byte = darkness_bytes [row % 4 + 1 ][col % 4 + 1 ]
814+ apple2 .SetDoubleHiresByte (row , col , byte )
815815 end
816816 end
817817end
818+
819+ -- Expect apple2.DHRDarkness() was previously called
820+ function apple2 .ValidateDHRDarkness (row , col )
821+ local expected = darkness_bytes [row % 4 + 1 ][col % 4 + 1 ]
822+ return apple2 .GetDoubleHiresByte (row , col ) == expected
823+ end
824+
818825---- ----------------------------------------------
819826
820827return apple2
0 commit comments