@@ -871,26 +871,91 @@ function apple2.SetDHRByte(row, col, value)
871871 apple2 .WriteRAMDevice (addr + 0x10000 * (1 - bank ), value )
872872end
873873
874- function apple2 . GrabTextScreen ( )
874+ function IterateTextScreen ( char_cb , row_cb )
875875 local is80 = apple2 .ReadSSW (" RD80VID" ) > 127
876- local screen = " "
876+ local isAlt = apple2 . ReadSSW ( " RDALTCHAR " ) > 127
877877 for row = 0 ,23 do
878878 local base = 0x400 + (row - math.floor (row / 8 ) * 8 ) * 0x80 + 40 * math.floor (row / 8 )
879879 for col = 0 ,39 do
880880 if is80 then
881- byte = apple2 .ReadRAMDevice (0x10000 + base + col )
882- byte = byte & 0x7F
883- screen = screen .. string.format (" %c" , byte )
881+ char_cb (apple2 .ReadRAMDevice (0x10000 + base + col ), isAlt )
884882 end
885- byte = apple2 .ReadRAMDevice (base + col )
886- byte = byte & 0x7F
887- screen = screen .. string.format (" %c" , byte )
883+ char_cb (apple2 .ReadRAMDevice (base + col ), isAlt )
888884 end
889- screen = screen .. " \n "
885+ row_cb ()
890886 end
887+ end
888+ function apple2 .GrabTextScreen ()
889+ -- Apple IIe and later, non-MouseText
890+ -- 0x00-0x1F: Inverse @ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_
891+ -- 0x20-0x3F: Inverse !"#$%&'()*+,-./0123456789:;<=>?@
892+ -- 0x40-0x5F: Flashing @ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_ (ALTCHAR - MouseText)
893+ -- 0x60-0x7F: Flashing !"#$%&'()*+,-./0123456789:;<=>?@ (ALTCHAR - inverse lower)
894+ -- 0x80-0x9F: Normal @ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_
895+ -- 0xA0-0xBF: Normal !"#$%&'()*+,-./0123456789:;<=>?@
896+ -- 0xC0-0xDF: Normal @ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_
897+ -- 0xE0-0xFF: Normal `abcdefghijklmnopqrstuvwxyz{|}~ `
898+
899+ local screen = " "
900+ IterateTextScreen (
901+ function (byte , isAlt )
902+ if byte < 0x20 then -- 0x00-0x1F: inverse upper
903+ byte = byte + 0x40
904+ elseif byte < 0x40 then -- 0x20-0x3F: inverse punctuation
905+ byte = byte
906+ elseif byte < 0x60 then -- 0x40-0x5F: flashing upper / MouseText
907+ if not isAlt then
908+ byte = byte
909+ else
910+ byte = 0x20 -- TODO: MouseText mapping
911+ end
912+ elseif byte < 0x80 then -- 0x60-0x7F: flashing punctuation / inverse lower
913+ if not isAlt then
914+ byte = byte - 0x40
915+ else
916+ byte = byte
917+ end
918+ elseif byte < 0xA0 then -- 0x80-0x9F: normal upper
919+ byte = byte - 0x40
920+ else -- 0xA0-0xFF: normal punctuation / upper / lower
921+ byte = byte - 0x80
922+ end
923+ screen = screen .. string.format (" %c" , byte )
924+ end ,
925+ function ()
926+ screen = screen .. " \n "
927+ end )
891928 return screen
892929end
893930
931+ function apple2 .GrabInverseText ()
932+ local str = " "
933+ IterateTextScreen (
934+ function (byte , isAlt )
935+ if byte < 0x20 then -- 0x00-0x1F: inverse upper
936+ byte = byte + 0x40
937+ elseif byte < 0x40 then -- 0x20-0x3F: inverse punctuation
938+ byte = byte
939+ elseif byte < 0x60 then -- 0x40-0x5F: flashing upper / alt: MouseText
940+ return
941+ elseif byte < 0x80 then -- 0x60-0x7F: flashing punctuation / alt: inverse lower
942+ if not isAlt then
943+ return
944+ else
945+ byte = byte
946+ end
947+ elseif byte < 0xA0 then -- normal upper
948+ return
949+ else -- normal punctuation / upper / lower
950+ return
951+ end
952+ str = str .. string.format (" %c" , byte )
953+ end ,
954+ function ()
955+ end )
956+ return str
957+ end
958+
894959function apple2 .SnapshotDHR ()
895960 local bytes = {}
896961 for row = 0 ,apple2 .SCREEN_HEIGHT - 1 do
915980
916981---- ----------------------------------------------
917982
983+ -- TODO: Implement BitsyInvokePath (tab to volume, then iterate on path segments)
984+
985+ function apple2 .BitsySelectSlotDrive (sd )
986+ while apple2 .GrabTextScreen ():match (" [^:]+" ) ~= sd do
987+ apple2 .TabKey ()
988+ emu .wait (5 )
989+ end
990+ end
991+
992+ function apple2 .BitsyInvokeFile (name )
993+ while apple2 .GrabInverseText () ~= name do
994+ apple2 .DownArrowKey ()
995+ emu .wait (1 )
996+ end
997+ apple2 .ReturnKey ()
998+ end
999+
1000+ ---- ----------------------------------------------
1001+
9181002return apple2
0 commit comments