mit2spr

1 rem Convert Menu Item to Sprite (GD2 only!)
2 rem ©pjwitte March 2oo4
3 rem V0.03, all GD2 modes, In-code menu
4 :
5 rem The function MkSpr is the functional part of this program
6 rem The rest is just a harness to test
7 :
10 ch = FOPEN("con_")
20 :
30 rem     Init GLOBal variables
40 llen = SCR_LLEN(#ch): base = SCR_BASE(#ch)
50 bpp = llen / SCR_XLIM(#ch): rem Bytes per pixel (1 or 2)
60 :
70 rem     Harness
71 DIM array$(20, 10)
72 FOR i% = 0 TO 20:array$(i%) = "Line " & i%
73 :
74 MDRAW#ch;  MyMenu: rem Load a suitable menu here
75 MAWDRAW#ch; 1, array$
76 :
77 wwd = MWDEF(#ch): rem Window Working Definition
78 cia = PEEK_L(wwd) + 56: rem $38 -> current item address
79 spr = 0: rem Init sprite address
80 :
81 REPeat test
82 k = MCALL(#ch, k, 0)
83 SELect ON k
84  = -1: QUIT
85  = REMAINDER
86    IF MKEY%(#ch) = 2 THEN
87     rem on DO
88     IF spr <> 0: RECHP spr: rem Forget previous sprite (if any)
89      spr = MkSpr(PEEK_W(cia), PEEK_W(cia + 2), PEEK_W(cia + 4), PEEK_W(cia + 6), 200)
90      SPRS#ch, spr: rem Make text sprite into pointer sprite
91    END IF
92 END SELect
93 END REPeat test
94 :
95 :
100 rem + ------------------------------------------------------------------------ +
110 rem |<                              Make Sprite                               >|
120 rem + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +
130 rem |                 Make a block of screen into a PE sprite                  |
140 rem |                                                                          |
150 rem | Given the coordines xs, ys, xo, yo, convert that block into a GD2        |
160 rem | sprite with transparency t% (t% = 0..255)                                |
170 rem |                                                                          |
180 rem | GLObal base, llen, bpp for speed                                         |
190 rem + ------------------------------------------------------------------------ +
200 rem | V0.01, pjw, 2004 Mar 13                                                  |
210 rem | V0.03, pjw, 2019 Mar 17, All GD2 screen modes                            |
220 rem + ------------------------------------------------------------------------ +
230 :
240 DEFine FuNction MkSpr(xs, ys, xo, yo, t%)
250 LOCal i, a, s, t, pixw
260 :
270 rem     Work out size
280 pixw = xs * bpp
290 IF bpp = 1: pixw = pixw + (pixw MOD 4)
300 s = base + yo * llen + xo * bpp
310 a = ALCHP(24 + (pixw + xs) * ys)
320 :
330 rem  Create sprite header
340 POKE   a + 0, 2:                rem GD2 sprite
350 POKE   a + 1, DISP_TYPE:        rem Mode
360 POKE_W a + 2, 32:               rem $0020 ..with alpha channel
370 POKE_W a + 4, xs: POKE_W a + 6, ys
380 POKE_W a + 8, xs DIV 2:         rem Centre sprite
390 POKE_W a + 10, ys DIV 2
400 POKE_L a + 12, 12
410 POKE_L a + 16, 8 + pixw * ys
420 POKE_L a + 20, 0
430 :
440 t = a + 24  :                   rem Sprite data goes here
450 :
460 rem  Now create sprite, one line at a time
470 FOR i = 1 TO ys
480  POKE$ t, PEEK$(s, pixw)
490  s = s + llen
500  t = t + pixw
510 END FOR i
520 :
530 rem  Create mask (ghost)
540 FOR i = t TO t + xs * ys: POKE i, t%: rem semi-transparent
550 :
560 rem sbytes_o 'ram1_t_spr', a, (24 + (pixw + xs) * ys)
570 RETurn a
580 END DEFine MkSpr
590 :
600 :
1000 DEFine FuNction MyMenu
1001 LOCal dad
1002 dad = ALCHP(322)
1003 :
1004 POKE_W dad + 0, 28677, 29439, 20033, 20085, 28005, 28277, 6, 28025, 28005, 28277
1005 POKE_W dad + 20, -30976, 255, 0, 0, 100, 158, 73, 77, 2, 1
1006 POKE_W dad + 40, 512, 513, 0, 1, 519, 524, 525, 0, 0, 520
1007 POKE_W dad + 60, 521, 0, 0, 522, 523, 0, 0, 0, 100, 158
1008 POKE_W dad + 80, 9, 11, 13, -1, 0, 12, 0, 104, 0, 134
1009 POKE_W dad + 100, 100, 24, 0, 18, 0, 0, 526, 527, 5, -1
1010 POKE_W dad + 120, 0, 4, 60, 10, 20, 3, 0, 528, 0, 21
1011 POKE_W dad + 140, 94, 10, 2, 13, 0, 528, 0, 9, -1, 0
1012 POKE_W dad + 160, 26, 0, 4, 15, 18537, 29728, 17519, 28261, 8308, 28448
1013 POKE_W dad + 180, 25966, 25600, 9, 17487, 8289, 8300, 26990, 25856, 40, 16
1014 POKE_W dad + 200, 30, 2, 0, 27, 9, 0, 0, -1, 0, 4
1015 POKE_W dad + 220, 4, 17519, 28261, 20202, 8, 5, 0, 0, 4, 92
1016 POKE_W dad + 240, 100, 4, 56, 0, 0, 534, 535, 0, 63, 0
1017 POKE_W dad + 260, 0, 0, 0, 0, 0, 0, 1, 519, 524, 525
1018 POKE_W dad + 280, 0, 0, 520, 521, 0, 0, 522, 523, 0, 0
1019 POKE_W dad + 300, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1
1020 POKE_W dad + 320, -92
1021 RETurn dad
1022 END DEFine MyMenu
1023 :
1024 :
  
Generated with sb2htm on 2019 Mar 17
©pjwitte March 2oi9