|
| 1 | +'Save and Load in all QBasic screen modes |
| 2 | + |
| 3 | +DECLARE SUB SaveScreenFile (filename$, ScreenMode%) |
| 4 | +DECLARE SUB ReadScreenFile (filename$) |
| 5 | +DECLARE FUNCTION GetScreenWidth% (ScreenMode%) |
| 6 | +DECLARE FUNCTION GetScreenHeight% (ScreenMode%) |
| 7 | +DECLARE FUNCTION ImageBufferSize& (x%, y%, x2%, y2%, ScreenMode%) |
| 8 | + |
| 9 | +SCREEN 1 |
| 10 | +LINE (0, 0)-(319, 199), 1, B |
| 11 | +CIRCLE (100, 100), 40 |
| 12 | +CIRCLE (150, 50), 40 |
| 13 | +CIRCLE (100, 150), 40 |
| 14 | + |
| 15 | +CALL SaveScreenFile("screen.img", 1) |
| 16 | + |
| 17 | +SCREEN 13 |
| 18 | +SCREEN 1 |
| 19 | + |
| 20 | +CALL ReadScreenFile("screen.img") |
| 21 | +SLEEP 5 |
| 22 | + |
| 23 | +FUNCTION GetScreenHeight% (ScreenMode%) |
| 24 | + SELECT CASE ScreenMode% |
| 25 | + CASE 1, 2, 7, 8, 13: GetScreenHeight% = 200 |
| 26 | + CASE 9, 10: GetScreenHeight% = 350 |
| 27 | + CASE 11, 12: GetScreenHeight% = 480 |
| 28 | + CASE ELSE: GetScreenHeight% = 0 |
| 29 | + END SELECT |
| 30 | +END FUNCTION |
| 31 | + |
| 32 | +FUNCTION GetScreenWidth% (ScreenMode%) |
| 33 | + SELECT CASE ScreenMode% |
| 34 | + CASE 1, 7, 13: GetScreenWidth% = 320 |
| 35 | + CASE 2, 8, 9, 10, 11, 12: GetScreenWidth% = 640 |
| 36 | + CASE ELSE: GetScreenWidth% = 0 |
| 37 | + END SELECT |
| 38 | +END FUNCTION |
| 39 | + |
| 40 | +FUNCTION ImageBufferSize& (x%, y%, x2%, y2%, ScreenMode%) |
| 41 | + myWidth& = ABS(x2% - x%) + 1 |
| 42 | + myHeight& = ABS(y2% - y%) + 1 |
| 43 | + SELECT CASE ScreenMode% |
| 44 | + CASE 1: BPPlane = 2: Planes = 1 |
| 45 | + CASE 2, 3, 4, 11: BPPlane = 1: Planes = 1 |
| 46 | + CASE 7, 8, 9, 12: BPPlane = 1: Planes = 4 |
| 47 | + CASE 10: BPPlane = 1: Planes = 2 |
| 48 | + CASE 13: BPPlane = 8: Planes = 1 |
| 49 | + CASE ELSE: BPPlane = 0 |
| 50 | + END SELECT |
| 51 | + ImageBufferSize& = 4 + INT((myWidth& * BPPlane + 7) / 8) * (myHeight& * Planes) 'return the value to function name. |
| 52 | + |
| 53 | +END FUNCTION |
| 54 | + |
| 55 | +SUB ReadScreenFile (filename$) |
| 56 | + OPEN "R", #1, filename$, 2 |
| 57 | + FIELD #1, 2 AS c$ |
| 58 | + |
| 59 | + GET #1 |
| 60 | + ScreenMode% = CVI(c$) |
| 61 | + GET #1 |
| 62 | + myWidth% = CVI(c$) |
| 63 | + GET #1 |
| 64 | + myHeight% = CVI(c$) |
| 65 | + |
| 66 | + size% = ImageBufferSize&(1, 1, myWidth%, 1, ScreenMode%) / 2 - 2 |
| 67 | + DIM ImageBuf%(size% + 2) |
| 68 | + pad% = LBOUND(ImageBuf%) |
| 69 | + |
| 70 | + ImageBuf%(pad%) = myWidth% |
| 71 | + IF ScreenMode% = 1 THEN ImageBuf%(pad%) = myWidth% * 2 |
| 72 | + IF ScreenMode% = 13 THEN ImageBuf%(pad%) = myWidth% * 8 |
| 73 | + ImageBuf%(pad% + 1) = 1 |
| 74 | + |
| 75 | + FOR j% = 0 TO myHeight% - 1 |
| 76 | + FOR i% = 0 TO size% - 1 |
| 77 | + GET #1 |
| 78 | + ImageBuf%(pad% + i% + 2) = CVI(c$) |
| 79 | + NEXT i% |
| 80 | + PUT (0, j%), ImageBuf% |
| 81 | + NEXT j% |
| 82 | + CLOSE #1 |
| 83 | +END SUB |
| 84 | + |
| 85 | +SUB SaveScreenFile (filename$, ScreenMode%) |
| 86 | + myWidth% = GetScreenWidth(ScreenMode%) |
| 87 | + myHeight% = GetScreenHeight(ScreenMode%) |
| 88 | + |
| 89 | + size% = ImageBufferSize&(1, 1, myWidth%, 1, ScreenMode%) / 2 - 2 |
| 90 | + DIM ImageBuf%(size% + 2) |
| 91 | + pad% = LBOUND(ImageBuf%) |
| 92 | + |
| 93 | + OPEN "R", #1, filename$, 2 |
| 94 | + FIELD #1, 2 AS c$ |
| 95 | + |
| 96 | + LSET c$ = MKI$(ScreenMode%) 'screen mode |
| 97 | + PUT #1 |
| 98 | + |
| 99 | + LSET c$ = MKI$(myWidth%) 'width |
| 100 | + PUT #1 |
| 101 | + |
| 102 | + LSET c$ = MKI$(myHeight%)'height |
| 103 | + PUT #1 |
| 104 | + |
| 105 | + FOR j% = 0 TO myHeight% - 1 |
| 106 | + GET (0, j%)-(myWidth% - 1, j%), ImageBuf% |
| 107 | + FOR i% = 0 TO size% - 1 |
| 108 | + LSET c$ = MKI$(ImageBuf%(pad% + i% + 2)) |
| 109 | + PUT #1 |
| 110 | + NEXT i% |
| 111 | + NEXT j% |
| 112 | + CLOSE #1 |
| 113 | +END SUB |
| 114 | + |
0 commit comments